- Home /
Why my GUI.Window is at the wrong location in the Editor?
I try to play with GUI.Window but when I run my application in the Editor, the Windows are at the bad position. I though my code was wrong but when i try to build it as a webplayer or standalone, the windows are well placed. Why ? Is that a known bug ?
Here a example which show a window center on the Screen...
private Rect windowHost = new Rect(Screen.width / 2 - 250, Screen.height / 2 - 250, 500, 500);
public void OnGUI() { windowHost = GUI.Window(1, windowHost, HostGame, "Host a Game"); }
public void HostGame(int windowID) { GUILayout.Label("Host Window"); }
Answer by Mike 3 · Jan 31, 2011 at 10:04 AM
The problem is that Screen.width and Screen.height don't immediately give the right values during construction of your class (And generally using functions/properties in member variable declarations is a very bad idea, so try not to do that anyway)
If you shift the rect declaration into OnGUI, it should fix it
Thank you very much. It works very well on my code. Best.