Stop Spawning Enemies When Player Dies
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.
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.
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.