Using Coroutines In Unity!
Functions in Unity are designed to run and return all in one frame. You can’t delay parts of the function or have it go on for multiple frames.
Like normal functions, coroutines are written in the syntax of: an optional access modifier, the return type, and the function name. The return type must be IEnumerator though.
Any coroutine must also include at least one yield return, if it is meant to span over multiple frames.
Using these, you can tell the program to wait until the next frame, wait until the next FixedUpdate function, wait for a specific number of seconds (real-time or game-time), wait until a condition is true, or wait while a condition is true.
To make the earlier example a functional coroutine:
Since coroutines are an ongoing process, they must be started using the StartCoroutine function, not called like normal, from any function.