56-Spawning Enemies in Waves

This post will describe how to spawn enemies in waves; with each wave, the number of enemies will increase.

To do so, first, three variables are defined as follows:

The currentWaveID tracks which wave we are at; the totalWaves defines the total number of waves; the arrange of enemiesInWaves defines the number of enemies being spawned in each wave, i.e., 3 in the first wave, 5 in the second wave, and 7 in the third wave.

To begin each wave, we also need a variable to track the enemies that have been spawned. For each wave, we will use a coroutine to spawn enemies until reaching the given number in the current wave. Since the condition to move onto the next wave is that all enemies in the current wave are killed, we need another variable to store the existing enemies. If that number goes to 0 (that is, all killed by the player), then we move to the next wave. Once the current wave ends, we will increment the currentWaveID and reset the spawnedEnemyInWave back to zero to start the next wave.

With the above implementation, a wave system with enemies coming in increasing numbers is implemented.

--

--

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
YShu

YShu

Technologist and Unity developer