Coroutines with Unity
A “Coroutine” is a method that can be put in a “Wait” state without causing the whole program to freeze up during the “Wait” period. The “Coroutine accomplishes this by yielding control back to the rest of the program during the waiting period.
From “void Start( )”, we call “StartCoroutine(myMsgCoroutine());, this starts IEnumerator myMsgRoutine(). Unity yields control back after “WaitForSeconds(3f);” reaches 3 seconds. “Hello World” is displayed in the “Console”. The process is repeated and in two seconds “Goodbye” is displayed in the Console Window. The Coroutine terminates itself when finished.