Help with Pause Menu script
I was following a tutorial from Brackeys on making a pause menu for my game
https://www.youtube.com/watch?v=JivuXdrIHK0&t=577s
However my pause menu doesn't work, so I was wondering if someone could spot any kind of error in the script that I may have made that I've missed.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PausedMenu : MonoBehaviour
{
public static bool GameIsPaused = false;
public GameObject pauseMenuUI;
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
if (GameIsPaused)
{
Resume();
}
else
{
Pause();
}
}
}
public void Resume()
{
pauseMenuUI.SetActive(false);
Time.timeScale = 1f;
GameIsPaused = false;
}
void Pause()
{
pauseMenuUI.SetActive(true);
Time.timeScale = 0f;
GameIsPaused = true;
}
public void LoadMenu()
{
Debug.Log("Loading Game...");
}
public void QuitGame()
{
Debug.Log("Quitting Game...");
}
}
Answer by Sgt_Spike · Jun 14, 2018 at 05:49 PM
Hmm, what do you mean by it's not working? I just created a new Unity project and copied this exact script in. When the escape key is pressed it appears, and when it is pressed again it disappears. That's what you want to happen right?
Are you sure you have the correct object referenced in the editor for 'PauseMenuUI', or perhaps you're getting an error in another script?
Thanks for the respose, I figured out that it wasn't actually an issue with the script, but that it wasn't set up properly in Unity, so I've sorted it now.
the same thing happened to me but different, "The variable pause$$anonymous$$enuUI of Pause$$anonymous$$enu has not been assigned. You probably need to assign the pause$$anonymous$$enuUI variable of the Pause$$anonymous$$enu script in the inspector." its supposed to work when i pressed escape but i cant understand why, at first i thought i needed to make a variable in the Pause$$anonymous$$enu game object but that didn't make sense, so i then thought there must be some missing script or something but no, i'm just a beginner at C# and i'm actually too young to be scripting, and its been days since i was trying to fix this so i hope you know the problem here.
Answer by GameHD_CoolTor · May 08, 2021 at 03:26 PM
You missed the "using UnityEngine.SceneManagement;"