Pause Menu


One quick feature I wanted to add is a pause menu inside the game. So this is a quick simple implementation.

It's a very simple implementation I just used "Time.timeScale = 0;". I made the variable in the PauseMenu class static, so I could access it in my PlayerAttack class. That way my player can't attack when the game is paused and the menu is up. I did have a button for Settings, but I've disabled that for now, it's low priority. The Exit button will go back to the main menu and the restart just reloads the current scene.


public class PauseMenu : MonoBehaviour 
{
     public GameObject PauseMenuPanel;
     public static bool isPaused;
     public void Pause()
     {
         // show panel
         PauseMenuPanel.SetActive(true);
         // pause time
         Time.timeScale = 0;
         // set flag
         isPaused = true;
     }
     public void MainMenu()
     {
         // go to main menu
         throw new NotImplementedException();
     }
     public void Resume()
     {
         PauseMenuPanel.SetActive(false);
         Time.timeScale = 1f;
         isPaused = false;
     }
     public void Restart()
     {
         SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
         Time.timeScale = 1f;
         isPaused = false; 
     }
     // Input class calls this when Escape is pressed
     public void OnCancel(InputValue input) => Pause();
 }

Leave a comment

Log in with itch.io to leave a comment.