I know I have been asking a lot lately, and that I should start answering unread forums to return the favor for so many answered questions. How do I close a window? I made a simple boolean, and a button inside the window to change that boolean..but it doesn't change a thing when clicked... Code (csharp): var GettingStartedRect : Rect = Rect (20, 20, 120, 50); var GUIstyle : GUIStyle; var Text1 : TextAsset; var ShowGettingStarted : boolean = true; function Start (){ transform.parent.GetComponent("MouseLook").enabled = false; GetComponent("MouseLook").enabled = false; Screen.showCursor = true; } function OnGUI () { // Register the window. Notice the 3rd parameter if(ShowGettingStarted){ GUI.Window (0, GettingStartedRect, DoMyWindow, "Getting Started"); } } // Make the contents of the window function DoMyWindow (windowID : int) { GUI.Label(Rect(10, 25, 100, 20), Text1.text, GUIstyle); GUI.DragWindow (Rect (0,0,10000,10000)); if(GUI.Button(Rect(395, 270, 100, 25), "Done")){ ShowGettingStarted = false; } }
I don't know that this has anything to do with your problem, but you've placed your button WAY outside of the window. You have if(GUI.Button(Rect(395,270,100,25)... I'm not an expert with using windows, but I believe the buttons position is relative to the window its in. Meaning (0,0,100,25) would put the button in the upper left corner of the window with a width of 100 and height of 25. Your window is only 120 pixels wide, but you have the button starting at 395 pixels away from the left edge. So! Try changing this: Code (csharp): if(GUI.Button(Rect(395, 270, 100, 25), "Done")){ to this: Code (csharp): if(GUI.Button(Rect(5, 5, 100, 25), "Done")){
I mean I adjusted the numbers to put the button inside the window. The window is 500x400, the button being 100x25, with a desired space of 5px around it. but the boolean remains true even after the button has been pressed. If I place the button in the OnGUI(), it works fine. But if it inside DoMyWindow(), it does not...