- Home /
Best practices for ending a game / dying / restarting
Hi - I have a simple game set up but there are various processes running from various scripts. I want to end the game if the character dies, making sure to do things like stop the timer, make sure the enemies stop looking for someone to kill, destroying the character game object, setting the score to zero, performing some sort of animation, maybe bringing up a menu, etc. Is there a good tutorial for that. Are there any functions I can leverage to just stop certain processes, or do I have to track down each function in each script and trigger something to accomplish the above? If so, what's a good way to handle triggers? Sorry, I know it's a big question and I don't mind doing research - just not sure where to look exactly.
You can use a GameObject which holds the game state (in an enum, probably) and have any relevant script refer to it. If you add the Application.DontDestroyOnLoad(this); to the object (preferably in the Awake() or Start() methods) it will keep going through the levels so you can always refer to it.
Depending on a lot of things you can just reload the level. This is dependent on not having lives to worry about and that your scene isn't too big, but its by far the easiest solution if your scene meets the requirements.
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
abit of a noobie question here 1 Answer
how to detect if a character has fallen / problem with triggers 1 Answer
i need to know how to make a menu 0 Answers
How to load (restart) last scene 2 Answers