I wrote this piece of code that i believe is pretty stable.
However when i go to play the game the pause menu has already popped up but its just the Canvas
and Time.timeScale
is still set as 1f;
Here’s my code:
public class NewBehaviourScript : MonoBehaviour
{
public static bool Paused = false;
public GameObject PauseMenu;
// Start is called before the first frame update
void Start()
{
Time.timeScale = 1f;
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyUp(KeyCode.Escape))
if (Paused)
{
Play();
}
else
Stop();
}
public void Stop()
{
PauseMenu.SetActive(true);
Time.timeScale = 0f;
Paused = true;
}
public void MainMenu()
{
SceneManager.LoadScene("Rat game save screen");
}
public void Play()
{
PauseMenu.SetActive(false);
Time.timeScale = 1f;
Paused = false;
}
}
Any idea why the pause menu is open when i start my game?
Please let me know because i have spent 4 hours on it already.