Hello,
I’ve got the following problem. In my project I’ve got a GUI window, that has a button. The button toggles another window (show on/show off). Something like this:
bool showAll = true;
bool show = false;
void OnGUI () {
if (!showAll) return;
// NOTE: the new window placed first to be drawn on top
if (show)
GUI.Window ( 1, new Rect(0, 0, 100, 100), InfoWindow, "Info" );
GUI.Window ( 0, new Rect(0, 0, 300, 300), MainWindow, "Main window" );
}
void MainWindow (int id) {
// ...
if (GUILayout.Button("Info")) show = !show;
//...
}
void InfoWindow (int id) {
//...
}
void Update () {
if (Input.GetKey(KeyCode.A)) showAll = !showAll;
}
So when I press the button the new window appears UNDER the old one, despite its order in OnGUI.
However, when both window a shown if I press “A” twice (turn off and on the whole GUI, then it draws windows in a correct order - “Info” appears ABOVE “Main window”).
The conclusion is simple - when I press the button on a main window its somehow thinks that it has some kind of “activity” and becomes on top of everything.
So the question is how do I get this work properly?
P.S. GUI.FocusWindow(1) - doesn’t help - the “Info” window appears “focused” under the main one ![]()