- Home /
How to make GUI.window appear after button click
Hey everyone, I am new to Unity still with the way UnityScript works. Im making an application that whenever a user clicks on an info button an information window appears instead of just having another scene being the window. Please help I think what I am missing is very simple but for the life of me I can not spot it but I am sure whenever I get the answer ill have a DOH moment! TY
function OnGUI()
{
if(GUI.Button(infoButton, "Info"))
{
GUI.color = Color.red;
infoWindow = GUI.Window (0, infoWindow, DoMyWindow, "Red Window");
}
}
function DoMyWindow (windowID : int)
{
if (GUI.Button (Rect (10,20,100,20), "information"))
print ("Got a click in window with color " + GUI.color);
// Make the window draggable.
GUI.DragWindow (Rect (0,0,Screen.width,Screen.height));
}
Answer by DaveA · Jul 18, 2012 at 10:14 PM
GUI.Button will only be true on the frame that the button is pushed, so the GUI.Window will only be called (displayed) on that frame.
Instead, have a boolean, like 'show' that goes true when you click the button. Then if show is true, call GUI.Window. If you need to close the window, have a key or button that will set show false again, that will stop calling (displaying) the window.
Your answer
Follow this Question
Related Questions
change button texture from different button press 1 Answer
GUI.Window only shows for one frame under all circumstances 2 Answers
Attack While Running 1 Answer
How to join the generators? 0 Answers