A Simple Wave System

In our game, we decided that a Wave system would be a good way to give the Player a since of progression.

So instead of the endless onslaught of enemies that we have had up to this point, the Player will experience clusters of enemies.

Now let’s see how we can setup a simple Wave system that is based on an amount of enemies to be spawned. Later we we can modify the system to allow for Boss fights and possibly even Mini Boss fights.

First, We will add some new variables to the SpawnManager Class to accommodate the new system. All three are fairly simple INTs. _waveCounts is a Serialized Array and will hold the intended amount of enemies for each wave. _spawnedEnemiesInWave will keep track of how many enemies get spawned so that we know when to stop spawning for any particular wave. _currentWave will be, as expected, our Wave count and by default starts at 0 since we will use it directly with the _waveCounts Array.

WaveStart() will be how we start each new Wave and end the game when the waves have finished. This is where we will handle the _spawning Bool that was previously set in Start(). As well, We reset the spawned Enemy Counter and Display the Wave Number at the start of each new wave. Note that we have to add 1 to _currentWave so that when Display shows it is “Wave 1” instead of “Wave 0”. Us coders will understand that 0 is a starting point for most things we do, but everyone else starts from 1.

In the StartSpawning(), we want to remove the EnemySpawnRoutine() and replace it with the WaveStart() since it is now controlling the EnemySpawnRoutine() itself.

Lastly, we have to modify our EnemySpawnRoutine() to work with the Wave spawning. We wrap the original routing in a second While statement that makes sure it doesn’t spawn more Enemy ships than is called for in the Wave. After the while loop, we want to check that the EnemyContainer Pool, were we have been storing our active enemies, is empty before we cycle to the next wave. This way we can insure that that the Player has killed all the Enemy ships before they are hit with another wave of them. We also add a Yield statement outside the IF so that the game doesn’t get stuck in a endless loop when the last enemy is spawned.

And With a single line added to the SpawnEnemy(), we are able to count when an Enemy is spawned into the Wave.

--

--

--

A Unity Developer with a fondness for Fantasy games and the challenge of pushing boundaries.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Top 10 Tips on Developing Your Problem Solving Skills and Levelling Up Your Coding!

Top CSS Code vs Real Pic Challenge

Chapter 7 Attorney

chapter 7 attorney

Sorting a Dictionary in Python

Introduction to Regression Analysis [using Excel]

ActionDash gains focus mode schedules, auto backup options & more

No more Software Engineer, Product Engineer is the new cool

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
Thomas Kesler

Thomas Kesler

A Unity Developer with a fondness for Fantasy games and the challenge of pushing boundaries.

More from Medium

Unity new Input System (Part II)

How to Make the Camera Shake Using Impulse Listener Extensions in Cinemachines Virtual Cameras

Bug Fix on Model Flip

Level Design in Unity 3D Part 3: Columns & Archways