I’m not sure if this is just a random bug on my part or if it’s happened to anyone else.
I’m trying to setup a GUI and positioning elements is becoming a pain. I wanted to initialize their positions in the Start() function. Elements are positioned according to the size of the screen. For example I’d use the following to try and get something positioned at the center of the screen.
as a debug i’d print the x and y value of Pos as well as the values of Screen.width and Screen.height and they are consistent. The crap hits the fan when I hit the OnGUI function. I put a debug line into it and the Screen.width and Screen.height are completely different from the start value. Should I just initialize the screen variables in the OnGUI call? Or am I just doing it wrong?
I assume you’re using Unity 3, which has a bug where using maximize on play returns the wrong results for Screen.width/height for the first couple of frames. You can either not use maximize on play, wait for a bugfix, or delay setting any values based on Screen.width/height for a few frames after start.
Confirmed that works. I tried it out with Eric5h5’s Vectrosity demo, I couldn’t hardly get any of them to work in the Scene view until I started running the scene with the “game” tab open. Gaaa buggers. Thanks for the work around DocSwab
Clarification: This workaround requires that the Game window be open and at full size. If there is any shrinking of the Game window in the editor prior to running with Maximize on Play checked, the sizes are reported in correctly.