Advertisement
LeeMace

Pause Screen

Dec 9th, 2022 (edited)
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.88 KB | Gaming | 0 0
  1. //in game manager
  2. // pause screen is a UI panel
  3. //pause menu
  4.     public GameObject pauseScreen;
  5.     private bool paused;
  6.    
  7.      void ChangePaused()
  8.     {
  9.         if (!paused)
  10.         {
  11.             paused = true;
  12.             pauseScreen.SetActive(true);
  13.             //game slows down to zero speed
  14.             Time.timeScale = 0;
  15.             //lets music play (doesn't require ref to audio source)
  16.             AudioListener.pause = true;
  17.         }
  18.         else
  19.         {
  20.             paused = false;
  21.             pauseScreen.SetActive(false);
  22.              //game plays at normal speed
  23.             Time.timeScale = 1;
  24.             //stops music playing (doesn't require ref to audio source)
  25.             AudioListener.pause = false;
  26.         }
  27.     }
  28.    
  29.      void Update()
  30.     {
  31.         if (Input.GetKeyDown(KeyCode.P))
  32.         {
  33.             ChangePaused();
  34.         }
  35.     }
Tags: ui pause
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement