- Home /
Make GUI box appear and disappear
Very newbie question. I'm trying to make a GUI box appear when I mouse over an object and disappear when the mouse is no longer on the object. I've been trying to do this by changing the alpha of the GUI box (though I feel like there may be a simpler way, like enabling and disabling the GUI...)
This is what I have so far:
var alpha = float;
function Start(){ alpha = 0;
}
function OnGUI() { GUI.skin.box.wordWrap = true;
GUI.color.a = alpha; GUI.Box(Rect(10,Screen.height/2+115,Screen.width-15,Screen.height/2-120),"text text text"); }
function OnMouseEnter () { alpha = 1; Debug.Log("mouse_enter"); }
function OnMouseExit(){ alpha = 0; Debug.Log("mouse_exit"); }
However my script is not responding to my "alpha" variable. I tried looking for a way to enable and disable the GUI, but there doesn't seem to be an easy way too. Or I'm missing something?
Answer by efge · Apr 19, 2011 at 09:48 AM
You could set a boolean variable to true or false depending OnMouseEnter/Exit and modify your OnGUI function like this:
function OnGUI() {
if (guiEnabled) {
... //draw GUI stuff
}
}
YESSSSS thank you so much!! you have no idea what a headache this has been.. very helpful for other scripts too, thank you.
Answer by robertmathew · Apr 19, 2011 at 09:28 AM
GUI.backgroundColor = Color(1, 1,1,0);
GUI.color.a =Mathf.PingPong(Time.time,1);
GUI.Button(new Rect(Screen.width *(0.2/6.55), Screen.height * (3.9/6.55),Screen.width * (.5/6.55), Screen.height * (.5/6.55)),GUIContent(playtexture,"playgame"));
Your answer
Follow this Question
Related Questions
Can I use a movie texture with alpha as a GUI object? 1 Answer
Distance activated GUI 1 Answer
GUI box not appearing when button is clicked 1 Answer
Why GUI Doesn't appears? 1 Answer
Strange shader behaviour on UI component 0 Answers