- Home /
How do I hide GUI?
I built a simple store with a trigger to detect when I go up to the counter. I also have this code on a panel GUI. I want the panel to be hidden at first, but I also want the trigger to show the panel when I go into it. I made sure the trigger works, it changes the variable Shopping to true, but I can't hide the GUI. I am probably using the wrong command. Can someone please tell me the right one?
#pragma strict
static var Shopping = false;
function Start () {
}
function Update () {
GUI.enabled = Shopping;
}
This is the panel in GameObject/UI/Panel On the top. I'm not very good at GUI, so I don't know exactly what you mean.
Are you using Unity 4.6 or 5, if using the new GUI then you'll be using a canvas.
I think you're probably using the old OnGUI that I'm not familiar with but if you are using the new 4.6 and newer GUI then I can help.
I was using the Canvas with 4.6. Sorry I replied late. I already got an answer from 'getyour411', but thanks anyway.
Answer by getyour411 · Dec 27, 2014 at 09:49 PM
Setup a variable, drag/drop panel reference in Editor
public Gameobject myPanel;
In Awake/Start/whatever set it to false
myPanel.SetActive(false);
In your trigger set it to true
myPanel.SetActive(true);
(and then false again on Trigger false condition)
Don't know JS
Thank you so much! It took me a while, put I was able to "translate" it to Javascript.
Answer by rezki · Dec 27, 2014 at 08:08 PM
before the line that does all the GUI.simply add
if(Shopping)
{
// Your GUI lines
}
Answer by JA_555 · Dec 28, 2014 at 03:52 AM
if you don't need any other GUI on the screen, you could just go to your camera and have a script uncheck the GUILayer. When you need the GUI gone just simply have:
GameObject.Find("Main Camera").GetComponent(Camera).GUILayer = false;
The layer solution appears to be faster then set active, even with multiple canvases. Simply move the canvas to a later that is not rendered.
I have more GUI on the screen, so that wouldn't work, but you gave me an easier to do it in the future if I need to.
Your answer
![](https://koobas.hobune.stream/wayback/20220613175005im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Unibill in-app purchase plugin, any experience? 3 Answers
I have a skin store where l want to put my animted charcter 0 Answers
StoreGUI problems 1 Answer
Hide GUI label on press 1 Answer