How To Make Enemies Spawn In Waves

A common approach to combat in games that is akin to the Arcade Genres of old utilizes a mechanic to spawn sets of enemies into the game at certain points. This is used to create a reprieve between stints of combat, as well give the player a feeling of accomplishment and/or progress.

For this example, I will be using a mixture of loops within coroutines to allow for delayed time intervals with WaitForSeconds().

When called upon, this coroutine checks if the player is alive with the “_stopSpawning” boolean variable. Then it begins spawning one enemy per second until it has spawned as many as indicated by the “_enemiesSpawnCount” integer variable. Once all enemies are spawned the method then exits the for loop and enters the next while loop. This loop is set to check if there are any more enemies alive every .1 of a second. Once all enemies have been killed this loop ends and the primary while loop waits for 2 seconds before starting again.

[Side Note]

This whole system could be customized/enhanced with all kinds of additional features. For example, you could switch out the instantiation of a singular enemy with a method that spawns a set, or random set of enemies.

Hi, my name is Adam Reed and I am a software engineer specializing in Unity and C# development. Feel free to scroll through and check out some of my work!

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

Recommended from Medium

Mario’s new tricks make Super Mario Odyssey a joy

VALORANT Patch Notes 2.06 Preview

img

LEC and LCS schedule for Summer Split announced

img

Updates on Twitch App (2019) parents need to know about

Critical Play: Walking Simulators

France and Team Vitality win Intel World Open Rocket League

img

Cloud9 and TSM Compete for the Last Spot at Worlds

Overwatch 2 Announced: New Heroes, Modes, Maps and More!

img

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
Adam Reed

Adam Reed

Hi, my name is Adam Reed and I am a software engineer specializing in Unity and C# development. Feel free to scroll through and check out some of my work!

More from Medium

What’s new in PVS-Studio in 2021?

OnCollisionEnter Vs. OnTriggerEnter — When to use them?

Top programming languages to choose for your future project in 2022