- Home /
Making GUI elements invisible
I need to make some GUI buttons invisible when no activity is detected from the user i.e. no mouse movement or keyboard input.
Is there a way to do this?
Answer by DaveA · Jan 26, 2011 at 10:58 PM
In your OnGUI function, you would just avoid the statements which would show the buttons, something like:
var activity : boolean = false;
function OnGUI() { ...
if (!activity) { var pressed = GUI.Button("ok"); ...
And it's up to you to set 'activity' true when you detect some activity. You could do this in the Update function by detecting key presses, mouse movement, mouse buttons, etc. and set to false when none are there, true if any are there. And I'd guess you'd want to put a bit of a delay on it too, perhaps half a second, such that the GUI doesn't flash as event do/don't happen.
Answer by Jake-L · Mar 13, 2011 at 12:00 PM
Another way is to use GUIStyle.none as the style. This is useful when you use GUILayout as it will preserve the position of other elements.
Answer by Bampf · Mar 13, 2011 at 12:23 PM
Note also that in cases where you want to draw none of the elements, you are better off deactivating the entire script, not just skipping lines. OnGUI has expensive setup, even when it doesn't end up drawing anything.
True assu$$anonymous$$g you're turning off all GUI elements not just some of them.
Your answer

Follow this Question
Related Questions
Small GUI Text Invisible in the Game View 0 Answers
Make part of the GUI become invisible 1 Answer
Turning off ONE GUI button 1 Answer
New Unity GUI has messed up the scene camera 2 Answers
How do you get sprite to appear on HUD when collected 1 Answer