Hop into Unity with Coroutines
There are many times that you want to delay a process and one of the most efficient ways to achieve this is with coroutines.
The first step is to declare an IENumerator method:
Anything you want to delay will go within this method. If you want to delay a fire rate, you can do that with a “WaitForSeconds” variable and having the code “yield” until that time has passed:
IENumerators don’t get called like regular methods. They are coroutines and need to be called with the “StartCoroutine()” call:
If you want a coroutine to run indefinitely, you would call it within the Start() mentod and have a while statement to keep it running:
This was the code used to create the title gif. Here you can see the JumpRoutine() called within StartCoroutine(). The JumpRoutine() itself is set for a neverending loop that will restart every 2 seconds.