x


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));
}
more ▼

asked Jul 18 '12 at 09:37 PM

Zach_Stoltz_PSU gravatar image

Zach_Stoltz_PSU
5 1 4 7

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Jul 18 '12 at 10:14 PM

DaveA gravatar image

DaveA
26.5k 151 171 256

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3460
x290
x201
x68
x34

asked: Jul 18 '12 at 09:37 PM

Seen: 848 times

Last Updated: Jul 18 '12 at 10:14 PM