The pause menu is getting shown by default when I click the play button, even though the GameIsPaused
boolean is set to false. I don't know if it's the fault of how I referenced it in the engine itself or how the script is written.
Here's how I referenced it in Unity:
And here's my code:
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class PauseMenu : MonoBehaviour
{
public static bool GameIsPaused = false;
public GameObject pauseMenuUI;
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
if (!GameIsPaused)
{
Pause();
}
else
{
Resume();
}
}
}
public void Resume()
{
pauseMenuUI.SetActive(false);
GameIsPaused = false;
Time.timeScale = 1f;
}
void Pause()
{
pauseMenuUI.SetActive(true);
GameIsPaused = true;
Time.timeScale = 0f;
}
public void LoadMenu()
{
Debug.Log("Loading Game...");
SceneManager.LoadScene("MainMenu");
}
public void QuitGame()
{
Debug.Log("Quitting Game...");
Application.Quit();
}
}