Advertisement
ChrisTutorials

Menu Manager (Unity C#) - Open / Close Menu by Key Press

May 23rd, 2018
4,467
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.66 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class MenuManager : MonoBehaviour {
  6.     // Changed to GameObject because only the game object of the menu needs to be accessed, you can
  7.     // change this to any class that inherits MonoBehaviour
  8.     public GameObject optionsMenu;
  9.    
  10.     // Update is called once per frame
  11.     void Update () {
  12.         // Reverse the active state every time escape is pressed
  13.         if (Input.GetKeyDown(KeyCode.Escape))
  14.         {
  15.             // Check whether it's active / inactive
  16.             bool isActive = optionsMenu.activeSelf;
  17.  
  18.             optionsMenu.SetActive(!isActive);
  19.         }
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement