Ogni Coroutine viene eseguita in completa indipendenza, condividendo le variabili.
Questo ci permette di generare comportamenti comnplessi senza utilizzare Update()
Creare un Empty Object e allegare lo script CoroutinesExample.cs
using UnityEngine; using System.Collections; public class CoroutinesExample : MonoBehaviour { public int mynumber = 0; void Start() { StartCoroutine(MyCoroutine()); StartCoroutine(MyCoroutineTwo()); } IEnumerator MyCoroutine() { print("MyCoroutine 0 sec"); print("Mycourotine number " + mynumber); yield return new WaitForSeconds(2f); print("2 sec"); mynumber++; yield return new WaitForSeconds(4f); print("4 sec"); } IEnumerator MyCoroutineTwo() { print("MyCoroutineTwo 0 sec"); print("MycourotineTwo number " + mynumber); yield return new WaitForSeconds(3f); print("3 sec"); print("MycourotineTwo number " + mynumber); } // ogni Coroutine viene eseguita in completa indipendenza, condividendo le variabili // print: // MyCoroutine 0 sec // Mycourotine number 0 // MyCoroutineTwo 0 sec // MycourotineTwo number 0 // 2 sec // 3 sec // MycourotineTwo number 1 // 4 sec }