I’ve got an iPhone project in U3.0 and the game tab screen is set to iPad resolution (1024x768). When I read Screen.width and Screen.height in code - running in the Unity IDE - I get 1192x635. If this is not what I should be using on iPad, where should I get the correct resolution? Or if this is where I should be getting the current resolution, how can I get it to report the correct values?
it will get the resolution the game window is set to, whatever that is.
Not sure if it’s related, but I have a 13 inch Macbook, and it can’t show the iPad’s full screen + the Unity IDE stuff. Parts of it get cropped, and Screen.height gives the size of the displayed screen. Pretty annoying. So I always set it to 4:3 instead of the actual resolution, and I check the ratio (width/height == about 4/3) to see if it’s an iPad screen.
It’s “set” to “iPad wide - 1024x768”. Evidently my monitor allows for more (and less, in respect of the Y axis) but that’s the setting I’ve chosen. How can I force the Window to be the size I’ve chosen? Even small resolutions like “iPhone small - 480x320” don’t work, so whether it’s too big or too small, Unity makes up its own mind what the screen size should be instead of using the size I’ve “set”.
I don’t see and iPhone small option in my game screen tab. It has Tall or Wide as the options for the original iPhone resolution.
Have you mis-quoted? Or is this an indication that something is wrong? Are you running Unity3f1, or an older beta?
I’m running 3f1. Yes, sorry, I did misquote. I’m going back and forth between two machines at the moment, so was going by memory. Which proved to be faulty.
EDIT: No, the values returned by Screen.width and Screen.height have no bearing on my resolution, the layout, the “set” resolution or anything. I just changed to the “tall” layout, and set to “iPad 1024x768” and my new screen width and height are 1920x20.
Ok, found the solution to this. I now get the values in Start() instead of including them in the field initializer. Not sure if this is a Windows/Mac issue or a Unity 2.6 / Unity 3.0 issue, but getting the values in the initializer works fine on Unity 2.6 on Windows, but produces random results on 3.0 on MacOS.
Probably an issue of my expectations rather than a bug, unless anyone disagrees?
sure you do it on start not awake?
If you did it in awake that would be errorous code as awake must not make any assumptions on the rest of the world and should not access anything outside itself either.
Thats what start is for and out of my experience that has so far worked but I didn’t test with f1 yet
That’s not the case…“Awake is called after all objects are initialized.” You can expect the screen to be initialized by the time Awake is called.
–Eric
I’m doing it in Start, but Awake seems to work as well. I was doing it with a field initializer (ie: float SW = Screen.width) and that is the only one which didn’t work. That actually seems sensible to me, and I think it was a mistake on my part to have put it there in the first place, but since it worked on Windows, I just assumed that it was ok.
Is the screen smaller at first but then gets “maximized on play”? Because I have noticed that in Start, it will still return the values of the smaller version.