Uniy3D Basics — Coroutines and Spawn Control
Coroutines are a special type of method that allows for the execution of code to happen intermittently. In contrast, a regular method in our scripts will run the code block inside of it in the span of one frame. This means that we have to create intricate systems if we want code to run over a length of time.
Unity defines Coroutines as:
A coroutine is like a function that has the ability to pause execution and return control to Unity but then to continue where it left off on the following frame.
Right now, we have our player and one enemy in the scene. Even by colliding with the player we essentially win the game. Congratulations, you can now sit back and wait for a major Studio to offer you a job!
Not satisfied?! Neither am I…Let’s build something better!
OBJECTIVE:
Create an extendable method to spawn enemies periodically.