2D Shooter: Creating a Spawn Manager

Sabrina Windsor
2 min readJun 2, 2021

--

The next step in making this game is to spawn more enemies in the game to shoot. Right now the enemy will only go back to the top of the screen if it hasn’t been destroyed, but once we destroy it we have no enemies. So let’s make something to we keep having something to shoot.

First we’ll need to make an empty object.

I already created the Spawn Manager, but that is what you should name the empty object. Now make a script for it, and open it up.

We’ll be making a Coroutine, and for that we will need to use a method known as IEnumerator. This will allow us to use the command Yield so we can make the program wait a certain amount of time before it starts over again. Without it, our loop will continue to repeat god knows how many time before it will just make the whole thing crash.

First, make a GameObject variable that’s private, but accessible using [SerializeField]. Name it “_enemyPrefab” and in the inspector drag the enemy prefab to the corresponding box in the SpawnManager gameobject.

Now in our IEnumerator method, we want to create a while loop. In it we need a variable where we want the enemy to spawn, to instantiate it, and a way to tell the program to wait before looping again.

Don’t worry about the _stopSpawning variable, we’ll get into it in a future article. Now all you need to do is write StartCoroutine(SpawnRoutine()); in the start method.

Then this should be able to happen!

--

--

Sabrina Windsor
Sabrina Windsor

Written by Sabrina Windsor

Currently learning to code with the help of GamedevHQ in order to someday my my game ideas come to life!

No responses yet