using System.Collections; using System.Collections.Generic; using UnityEngine; public class PauseMenu : MonoBehaviour { public MonoBehaviour PlayerMovement; //reference to playermovement public static bool GameIsPaused = false; //bool for if the menu is opened public GameObject pauseMenuUi; //reference to pauseMenuUi void Start() { pauseMenuUi.SetActive(false); //hiding the menu if (PlayerMovement != null) { GameIsPaused = PlayerMovement.enabled; //set game is paused to true if playermovement is disabled } } void Update() { if(Input.GetKeyDown(KeyCode.Escape)) //check if menu is opened { if(GameIsPaused) { Resume(); //resume if the menu is already open } else { Pause(); //pause if the menu is closed } } } void Resume() { pauseMenuUi.SetActive(false); //hide menu Time.timeScale = 1f; //continue time GameIsPaused = false; //games not paused PlayerMovement.enabled = true; //enabling player movement } void Pause() { pauseMenuUi.SetActive(true); //show menu Time.timeScale = 0f; //stop time GameIsPaused = true; //game is paused PlayerMovement.enabled = false; //disabling player movement } }