Objective: Starting and Stopping a Coroutine

Having some fun with some coroutines. Here is something you should walk away with.

It’s easy to start a coroutine. All you have to do is create a coroutine, do some sort of action, and have a yield return for it to be valid. But how do you pause a coroutine? You have to declare it as a variable.

Declare the _spawnRoutine as a variable at the start of the script and have _spawnRoutine grab the SpawnRoutine() function. Then in your script, all you have to do to stop the coroutine is to run the following:

We can also stop a coroutine in the while loop above as well