Need to press 3 times to pause in-game in Unity
I have the problem that my game won't pause or show my pause screen until I have pressed the escape key three time after starting the game. After that it works perfectly. I have tried to Debug my paused variable, the timescale and debuged to check if I went into certian function. I saw that everything works like it should, it executes the Pause function and gets into the different if statements and even changes the Paused variable like it should, but for some reason it totally ignores to change the timescale and show the pausemeny until 3 times later... I have no idea what's making this happen. Any suggestions for what I could do would be much appreciated.
public GameObject PauseM;
bool Paused = false;
void Start()
{
PauseM.SetActive(false);
Time.timeScale = 1.0f;
Paused = false;
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
Pause();
}
}
public void Pause()
{
if (Paused == true)
{
Debug.Log("Unpaused");
Time.timeScale = 1.0f;
PauseM.SetActive(false);
Paused = false;
Cursor.lockState = CursorLockMode.Locked;
}
else
{
Debug.Log("Paused");
PauseM.SetActive(true);
Time.timeScale = 0.0f;
Paused = true;
Cursor.lockState = CursorLockMode.Confined;
}
Debug.Log(Paused);
}
public void Reset()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
public void Quit()
{
SceneManager.LoadScene(0, LoadSceneMode.Single);
}
Your answer
Follow this Question
Related Questions
Pause Menu 1 Answer
How do i stop my mouse from being in first person when a pause menu appears? 0 Answers
How do I detect if an Admob Banner Ad has been tapped/opened? 1 Answer
Pause Game and enable image 0 Answers
How can I make sure that the game is selected after closing out of a pause menu? 0 Answers