- Home /
Question by
VariantPolygon · Mar 29, 2021 at 04:03 PM ·
timepause menupause gamepausing
Setting timeScale to 0 causing editor to freeze
I'm using this script I wrote a while back, but for some reason occasionally the editor and game completely freezes and I can't un pause. This use to work fine for a while, but not it freezes causing me to force quit Unity. Any ideas why this may be occurring?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
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)
{
Resume();
} else
{
Pause();
}
}
}
void Resume ()
{
pauseMenuUI.SetActive(false);
Time.timeScale = 1f;
GameIsPaused = false;
Cursor.visible = false;
AudioListener.pause = false;
}
void Pause ()
{
pauseMenuUI.SetActive(true);
Time.timeScale = .0f;
GameIsPaused = true;
Cursor.visible = true;
AudioListener.pause = true;
}
}
Comment
Your answer
Follow this Question
Related Questions
Pause game when user pulls down the notification panel 0 Answers
Buttons will not change color 11 Answers
Time.realTimeSinceStartup behaves weirdly when sending app to background or locking the screen. 1 Answer
How to make a pause menu with Gui Texture?? 2 Answers
hard to explain but, when my game is paused my space bar goes weird. 0 Answers