Day 9 of my Developer Journey: Stop spawning once the player dies

Now that we have a functioning spawning system, we need it to stop once the player dies. We will be using a more complicated of the GetComponent method.

Firstly, we will add a bool variable to our Spawn managers infinite loop.

Stop spawning variable implementation

Next we add a method that changes this variable.

New OnPlayerDeath method

Now we need to communicate with this code from the player’s code. First we add a variable for the method, so that we can globally interact with the method.

SpawnManager variable

Next in the void start method we search for and assign this variable, while also setting up a null check.

Assign the variable a value

Finally we communicate with the variable in the Damage method. Once it triggers, the value for our _stopSpawning variable to true, turning off the infinite loop.

Triggering the variable through the if statement

--

--