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

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response