Enabling/Disabling Canvas for Game Over Menu
Hello, I'm a musician at heart and programming is a major challenge for me. I've seen lots of posts on the forum about enabling/disabling a canvas (or I guess gameobject) to show a game over screen. I am attempting the same thing, but still after fixing many typos I'm having the same persistent issue. When I load the scene, the game over canvas is disabled by default, then enabled if lives < 1. This all works fine but when I hit the restart level button the game over window appears at the beginning of the scene. I have a line for canvas.gameObject.SetActive (false), but the error that pops up is that variable canvas has not been assigned to game manager, but I always check to see if it is and it's in the game manager (or else I guess it wouldn't appear in the first place). Would appreciate any help for a noob!
{ bool gameHasEnded = false;
//canvas is variable for game over canvas
public GameObject canvas;
//if livesValue < 1
public void EndGame ()
{
if (gameHasEnded == false)
{
Debug.Log ("Game Over");
gameHasEnded = true;
canvas.gameObject.SetActive (true);
Time.timeScale = 0;
}
}
//functions for game over menu buttons
public void RestartLevel ()
{
SceneManager.LoadScene ("Demo_Scene");
canvas.gameObject.SetActive (false);
Time.timeScale = 1;
}
public void LoadMainMenu ()
{
SceneManager.LoadScene ("Main_Menu");
}
}
Hi @epajer55 - What kind of scene setup you have? Do you have one or multiple scenes? Where you run your RestartLevel?