Advertisement
Guest User

Unity Canvas Toggle

a guest
Jan 11th, 2017
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.64 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. public class ExitMenu : MonoBehaviour
  4. {
  5.     // Get the canvas game object
  6.     public GameObject canvas;
  7.  
  8.     // Update is called every frame
  9.     void Update()
  10.     {
  11.         // If the user pressed the escape key
  12.         if (Input.GetKeyDown(KeyCode.Escape))
  13.         {
  14.             // If the canvas is already active
  15.             if (canvas.activeSelf == true)
  16.             {
  17.                 // Disable the canvas
  18.                 canvas.SetActive(false);
  19.             }
  20.             else
  21.             {
  22.                 // Enable the canvas
  23.                 canvas.SetActive(true);
  24.             }
  25.         }
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement