- Home /
Question by
Mangospank · Feb 26, 2017 at 01:22 PM ·
guisetactive
Change GUI menu from one to the other
I've got an Inventory GUI that opens when hitting "E" and an Exit GUI that opens when hitting "Escape". I want one to close while the other opens when their related button is pressed. I've achieved this some what by adding GameObject.SetActive(false); to each button but I have to double tap each button. I press "Escape" once, it hides the Inventory, I then have to press it again to show the Exit GUI, and vise versa.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ActivateGUI : MonoBehaviour {
public GameObject inventory;
public GameObject exitMenu;
private bool isShowing;
void Update()
{
if (Input.GetKeyDown(KeyCode.E))
{
isShowing = !isShowing;
inventory.SetActive(isShowing);
exitMenu.SetActive(false);
}
if (Input.GetKeyDown(KeyCode.Escape))
{
isShowing = !isShowing;
exitMenu.SetActive(isShowing);
inventory.SetActive(false);
}
}
}
Comment
Your answer
Follow this Question
Related Questions
physics.OverlapSphere colliders 1 Answer
Trying to enable an input-field, once disabled. 1 Answer
SetActive and prefabs not working 1 Answer
Show Gui after amount of time 2 Answers