Developer blog

StopCoroutine not working

After playing around with StartCoroutine to spawn different kind of game objects i had some trouble using StopCoroutine to halt the spawning. My first try was to use StopCoroutine right away, the same way that StartCoroutine is used:

This will not work. To Use StopCoroutine there are two alternatives. The first alternative is to stop all Coroutines in the MonoBehaviour by using StopAllCoroutines();

This may however not be the wanted behaviour, there might be other coroutines that should continue to run. To accomplish this we need to keep a reference to the coroutine instance and use that to stop it: