Stop Spawning Enemies When Player Dies

Rusben Guzman
May 24, 2021

--

In this project I have a spawn manager to spawn the enemies during the game. Now we’re gonna add a condition to stop spawning enemies when the player dies.

Game continue spawning enemies when the player dies

We’re gonna create a bool variable to determine if we have to stop spawning and a function to change the value of that variable.

Then we have to add the condition to the spawning coroutine to spawn enemies when _stopSpawning will be true.

Adding condition to stop spawning when _stopSpawning = true

In the player controller we have to create a variable to get the spawn manager script component using the function get component. After that we have to call the OnplayerDead() Function when we check when the player dies.

And that’s it, now the game stops spawning enemies when the player dies.

--

--

Rusben Guzman
Rusben Guzman

Written by Rusben Guzman

A Software Engineer passionate about game dev and interactive products with Unity. I consider video games to be the artistic expression of programming.

No responses yet