Phase 2 — Wave System

Nicholas Lim
2 min readJun 14, 2021

--

The enemies will spawn in waves, and the game will announce the start of each wave.

To begin, we add a new Text element to the UI Manager that will display the wave via a coroutine, for three seconds.

UI Manager script

The main meat of the wave functions are in the Spawn Manager, which now needs to know about the UI Manager to call that coroutine to display the wave text.

Spawn Manager script

The SpawnEnemyRoutine coroutine also waits for three seconds before spawning enemies. The amount of enemies it spawns is passed in via the amountToSpawn int argument, which starts at 3. The Spawn Manager also initializes the _enemiesLeft variable with the same value.

As the game spawns enemies, amountToSpawn is decremented, until it hits zero, stops spawning, and it’s up to the player to clear the map of enemies.

In the Enemy script, each time an enemy dies, it calls the DecrementEnemyCount method, which does what it says on the box. When _enemiesLeft hits zero and there are still waves to spawn, it increments the current wave, increases the amount of enemies to spawn by another 3, and starts another spawning coroutine.

Enemy script

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response