Advertisement
thegreen9

UNITY pause menu

Mar 28th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.68 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.SceneManagement;
  5.  
  6. public class PauseMenu : MonoBehaviour {
  7.  
  8.     public GameObject ui;
  9.     public GameObject canvas;
  10.     void Update () {
  11.         if(Input.GetKeyDown(KeyCode.Escape)){
  12.             Toggle();
  13.         }
  14.     }
  15.     public void Toggle(){
  16.         canvas.SetActive(false);
  17.         ui.SetActive(!ui.activeSelf);
  18.         if (ui.activeSelf)
  19.         {
  20.             Time.timeScale = 0f;
  21.         } else
  22.         {
  23.             Time.timeScale = 1f;
  24.             canvas.SetActive(true);
  25.         }
  26.  
  27.     }
  28.     public void Retry()
  29.     {
  30.         Toggle();
  31.         SceneManager.LoadScene (SceneManager.GetActiveScene().buildIndex);
  32.     }
  33.     public void Menu()
  34.     {
  35.         SceneManager.LoadScene("MainMenu");
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement