Advertisement
Guest User

pause

a guest
Dec 1st, 2015
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2.  using UnityEngine;
  3.  
  4.  public class pause : MonoBehaviour
  5.  {
  6.      bool paused = false;
  7.  
  8.      void Update()
  9.      {
  10.          if(Input.GetButtonDown("escape"))
  11.              paused = togglePause();
  12.      }
  13.      
  14.      void OnGUI()
  15.      {
  16.          if(paused)
  17.          {
  18.              GUILayout.Label("Game is paused!");
  19.              if(GUILayout.Button("Click me to unpause"))
  20.                  paused = togglePause();
  21.          }
  22.      }
  23.      
  24.      bool togglePause()
  25.      {
  26.          if(Time.timeScale == 0f)
  27.          {
  28.              Time.timeScale = 1f;
  29.              return(false);
  30.          }
  31.          else
  32.          {
  33.              Time.timeScale = 0f;
  34.              return(true);    
  35.          }
  36.      }
  37.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement