You print values ββfrom 1 to 30 with a delay of 0.52 seconds, but after 2 seconds you stop doing this (you call StopAllCoroutines
). That is why you see only 1, 2 and 3.
Try commenting StartCoroutine (CoroutineKiller (2f));
or give it more time to see how it controls the flow stop.
Coroutines is similar to threads, although not very, but in the sense that a call StartCoroutine
does not block the code.
So when you do this:
void Start ()
{
StartCoroutine (MyCoroutine (0.52f));
StartCoroutine (CoroutineKiller (2f));
}
, , .
, :
void Start()
{
StartCoroutine(F());
}
IEnumerator F()
{
yield return StartCoroutine(MyCoroutine(1.52f));
yield return StartCoroutine(Killer(2f));
print("done");
}
Execution Order , , .