http://unitypatterns.com/introduction-to-coroutines/
http://unitypatterns.com/scripting-with-coroutines/
Notes
So if you are new to Coroutines, I hope these two tutorials helped you wrap your head around how they work and how they can be put to use. Here are some additional things to keep in mind while using Coroutines:
- You can only call StopCoroutine() on a routine started by string name
- Multiple Coroutines can be run simultaneously, they will update in the order they were started
- Coroutines can be nested as deep as you need (we only nested one level deep in this example)
- If you want a Coroutine to be accessed from many scripts, you can make them static
- Though they might appear to be so, Coroutines are not multi-threaded, they run on the same thread as your regular scripts
- If you have processes that require a lot of computation, consider calculating them over time with a Coroutine
- IEnumerator functions can not have ref and out parameters, but they can take passed references
- There is currently no easy way in Unity to detect how many and what Coroutines are currently running on an object (be careful!)