I’ve got a GUI.Window
set up with a static Rect declared at the top of my class, like such:
private const int MAP_WINDOW_ID = 2;
private const float MAP_WINDOW_HEIGHT = 590.0f;
private const float MAP_WINDOW_WIDTH = 825.0f;
private static Rect mapWindowRect = new Rect((Screen.width / 2) - (MAP_WINDOW_WIDTH / 2),(Screen.height / 2) - (MAP_WINDOW_HEIGHT / 2),MAP_WINDOW_WIDTH,MAP_WINDOW_HEIGHT);
I’ve been getting really random values for the calculated offset. I put a Debug.Log(mapWindowRect)
on the Start
method to verify and I’ll get different values almost every time the game starts up. So, I’m obviously doing something wrong, where the height and width are maybe in the process of being set maybe?
Either way, here’s my question:
Why is this happening, and how do I avoid it so I can center windows and other gui elements based on the user’s screen rather than hard coded?