More enemies, using a Coroutine!
Having just a single enemy wouldn’t be much of a game now, would it?
Having gotten all the basics down, it’s time to add more enemies. In Unity, we can use something called coroutines. We can use them to run methods that have the ability to be paused, while the rest of the game is still doing its thing.
Creating a SpawnManager
I decide to create a new class and gameobject to handle the spawning of enemies, I shall call it “SpawnManager”.
The coroutine uses a type of interface called IEnumerator, not to be confused by the IEnumerable which will not work here 😅
There is something called the yield keyword, this is what is telling the coroutine to pause. Outside of that, it behaves just like a normal method.
The enemy is already made into a prefab, so now I have to let the spawn manager know what it is supposed to spawn, where, and how often.
I make sure that the enemies are spawned at a random location on the X-axis at a set height above the camera's view.
Now that the basics are done, we’ll make a go at switching this over to 2D with better visuals next time 😄