I have a window that should have a "close window" button. The close button works if its outside the window (in the OnGUI function like the openWindow is), but not when its inside it (like in example).
var windowOpen = false;
function OnGUI () {
var windowRect : Rect = Rect (20, 280, 349, 130);
if(GUI.Button(Rect(495,270,9,9), "Open Window")) {
ShowWindow();
}
if (windowOpen) {
windowRect = GUI.Window (0, windowRect, drawWindow, "Window Title");
}
}
function drawWindow () {
// Here be some window content like text and a pic
if (GUI.Button (Rect (235,104,50,22), "Close")) {
HideWindow();
}
}
public function ShowWindow() {
windowOpen = true;
}
public function HideWindow() {
windowOpen = false;
}
I found one similar case where the fix was to change position of the last function call, but I couldn't figure how to relate it into my problem. http://forum.unity3d.com/threads/78556-How-to-close-a-window
Make sure your Open Window button is not somehow in the same place as Close? Doesn't look like it though. I may just have to try this myself, because it looks like it should work.
– DaveA