I’m trying to get my pause menu to open and close when the player presses the “p” key. The buttons on the pause menu work to take you to the main menu and quit the game, but for some reason, the menu won’t activate/deactivate once the “p” key is pressed. At first I created the menu in its own scene, but I’ve added it to my level to see if it would make a difference (it didn’t)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class PauseMenu : MonoBehaviour
{
public static bool GameIsPaused = false;
public GameObject PauseMenuBehavior;
void Update()
{
if (Input.GetKeyDown(KeyCode.P))
{
if (GameIsPaused)
{
Resume();
}
else
{
Pause();
}
}
}
public void Resume()
{
PauseMenuBehavior.SetActive(false);
Time.timeScale = 1f;
GameIsPaused = false;
}
public void MainMenu()
{
Time.timeScale = 1f;
SceneManager.LoadScene("Main_Menu");
}
void Pause()
{
PauseMenuBehavior.SetActive(true);
Time.timeScale = 0f;
GameIsPaused = true;
}
public void QuitGame()
{
Application.Quit();
Debug.Log("Quitting game...");
}
}