KeyDown UI

Updated on July 19, 2017 in [A] GUI
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
2 on July 19, 2017

I need help with making a script that activates a UI when you press a key. and it closes when you press that key again or the escape key.

  • Liked by
Reply
1 on July 19, 2017

In the Update function you could make a if statement with a check for a Input.GetKeyDown and then toggle the gameobject GameObject.SetActive(true/false).

 

https://docs.unity3d.com/ScriptReference/Input.GetKeyDown.html

https://docs.unity3d.com/ScriptReference/GameObject.SetActive.html

 

on July 19, 2017

thats what i did:

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MenuManager : MonoBehaviour
{
 public GameObject escapeMenu;
void Update()
 {
 if (Input.GetKeyDown (KeyCode.E)) {
 escapeMenu.SetActive (true);
 }
else
 {
 escapeMenu.SetActive (false);
 }
 }
}

 

 

Show more replies
  • Liked by
Reply
Cancel