- Home /
Correct way to broadcast player death across multiple game objects
I have an infinite runner where it continuously spawns multiple trees moving up (sorta like the asteroids in the Space Shooter tutorial). If the player runs into the scrolling trees, I want the trees to all stop moving as well as the background. What is the correct way to do so? Currently only my GameController is aware of the gameOver variable. Do I -
Declare a GameController reference in each tree instance?
Move the gameOver variable into a singleton and reference that from each tree instance?
Other better suggestion?
Not sure of best practices, any help is appreciated! Thanks
Answer by tadejP · Aug 03, 2017 at 01:44 PM
You could just declare a static variable in the tree script, which would influence whether trees move or not. If you want more flexibility you can use events https://unity3d.com/learn/tutorials/topics/scripting/events