- Home /
Question by
annonymushubh · Jul 29, 2017 at 07:00 AM ·
unity 5fpsgameover
i want to when game is over every thing stop
i have a fps game i want to add with player health is empty every thing is stop and show the game panel
Comment
Answer by Hanoble · Jul 29, 2017 at 07:46 AM
There are several ways to do this but I will propose a rather simple one. In your manager script, or wherever this logic is you want to stop running, add a gameOver bool to the class and in the Update() method just return if the game is over. To open the game panel, in the same method that sets the gameOver bool just insert your code to open the game panel there. Something along the line of this:
public class GameManager : Monobehaviour
{
private bool gameOver;
void Update()
{
//If the game is over do not run the game logic
if(gameOver)
return;
//All of your logic running when the game is actively playing here
}
//This method is called when the game over condition is met, in this
case when a player takes damage and their health is below 0
void EndGame()
{
gameOver = true;
//Treating the game panel as a basic gameobject here, but the idea is
to end the game and set the panel to active
gamePanel.SetActive(true);
}
}