Nerd For Tech
Published in

Nerd For Tech

Unity Guide

Implementing space shooter game features - Enemy waves

A quick review of new features added to a space shooter game in Unity

Objective: Implement a new system to spawn enemies in a space shooter game with Unity.

In the previous post I implemented a new movement behavior for the enemies in my space shooter game with Unity. Now it’s time to implement a new system to spawn the enemies in different waves.

Wave warning

In an older post, I covered how to make a retro game over behavior, which gives the game over warning a blinking behavior when the player gets destroyed:

I used coroutines to do that effect, but now, I’ll use another method to achieve the same behavior and make it possible to use it in two or more Text elements without having to customize the respective method.

To start, let’s add a new Text element for the Wave warning:

Note: I added a new font to my game, if you want to add a new font you can check a site like this to choose one you like. Don’t forget to check the license of the font.

The next method is the coroutine that handled the game over retro behavior when it was executed:

Now, after getting rid of the coroutine, let’s create a new animation for the blinking effect in a Text element. To do that, we need to create it in an Animation window, where we’ll select to add the Text.Enabled property and modify it throughout the keyframes to achieve the blinking effect:

Also, to control the blinking animation state, I added a Start and a Stop trigger to the animation controller.

Then, in order to disable the respective Text element after the Stop trigger is called, I added a new behavior script to the blinking animation state:

This script, which needs to be inherited from StateMachineBehaviour to be attached to the state, will disable the gameobject when the Text element leaves the blinking state (which is when the Stop trigger is set):

If you want to know more about this class you can visit the Unity docs:

This way, we can make sure to control the blinking animation for the time we want like this:

Wave implementation

In order to implement the wave of enemies, let’s open the spawn manager script and modify the current enemy spawn coroutine to receive the number of enemies to spawn and the respective delay to wait before spawning each enemy:

Therefore, in order to initialize a new wave, we need to provide the respective parameters:

Now, let’s open the game manager script:

Here, we’ll need some variables to manage the wave system and a reference to the spawn manager:

This way, we can edit the number of waves and enemies added per wave through the inspector:

Now, to manage the wave warning and the wave spawning, let’s use a new coroutine which will display the warning using the UI manager and then it will spawn the new wave using the spawn manager:

In order to handle the current wave, let’s use a new public method that will be called by an enemy before getting destroyed. This way we’ll be able to update the enemies to destroy per wave and call the next wave after they’ve been destroyed:

Finally, let’s add a public method to start the game when it gets called:

Now, if we call this method after destroying the asteroid, we’ll see that the wave warning and system work as expected:

And that’s it, we implemented a wave system to spawn the enemies! :D. I’ll see you in the next post, where I’ll be showing more features added to my space shooter game in Unity.

If you want to know more about me, feel free to connect with me on LinkedIn or visit my website :D



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Fernando Alcantara Santana

Fernando Alcantara Santana


A passionate computer technology engineer and Unity developer that is always looking to grow in every aspect of life :).