Screen.width and Screen.height reversed on Iphone

I’m trying to create a GUI for my game but I’ve ran into an issue. It seems like the values for Screen.width and Screen.height are reversed when played on the Iphone vs the editor.

Even the docs state vertical orientation screen is treated as 480x320 for iPhone and horizontal orientation as 320x480 for iPhone.

Isn’t that the opposite of what it should be? Shouldn’t horizontal be 480x320?

In the editor Screen.width = 480
On the iphone Screen.width = 320

The editor is set to Iphone Wide and the default orientation is landscape.

horizontal should be 480x320 and commonly is actually at least I’ve not had any case where it isn’t.

perhaps you forgot to disallow the other orientations or alike?

I found the problem was using it in the declaration of a variable like this:

private var fireGunBounds : Rect = new Rect(Screen.width*0.5f, Screen.height*0.5f, Screen.width*0.5f, Screen.height*0.5f); // right stick bounds

It gives reversed values. If you use them in the start function they work as expected. I think that is just a typo in the docs.

not sure if a typo but a known thing that you should not use such stuff in there as the static initializers are called very early.
In U2 / IPHone 1.x it was no problem but in U3 it seems like screen gets filled with the correct data very late actually

Unity 3.0/3.1 has a bug with Maximize On Play, where the values are incorrect for the first couple of frames. If you don’t use that (and outside the editor), there’s no problem.

–Eric

I’m having a similar issue after updating Unity to version 3.5.2f2.

The Screen.width and Screen.height reversed on iPhone but correct on iPad.

That’s (should be) only true if you start your app in portrait mode, and android had the same problem even on 3.5.1…

Take a look at that thread

http://forum.unity3d.com/threads/136088-How-to-Fix-the-3.5.2-Rotation-Problem

I have also seen issues with requesting Screen.width and Screen.height. I now add a 1-2 frame pause after waking up to ensure that these values have been set correctly. I had issues where the width/height would give me all sorts of crazy values - completely bogus.

According to other threads, this is even worse in 3.5.2.

Gigi.

+1 here for someone else affected by this… How are you dealing with it?

it’s better to use “camera.pixelWidth” and “camera.pixelHeight” instead of screen.width/screen.height. Camera.pixelWidth works perfectly for me… no issues.

It seems that in unity 5.0.2p4, on ipad2 ios 7 at the first frame Screen.Width and Screen.Height are inversed. Then the value is right.

ios 7 at the first frame
it might totally happen. on pre-ios8 (unless iirc you force orientation) it starts in portrait and then is rotated. and we do start frame a bit too early for lots of reasons.