- Home /
Random screen height and width when platform is set to IOS.
I have my game view set for iPhone5 Tall(9:16) size. In the script when I am checking the width and height of screen, I get unknown width and height. Here's the code that I've used:
function Start ()
{
Debug.Log( "ScreenWidth:" + Screen.width + "ScreenHeight:" + Screen.height);
}
In the Editor, I get this for iPhone 5(9:16) - ScreenWidth:203ScreenHeight:361 and for iPhone 4 Tall(640*960) - ScreenWidth:240ScreenHeight:361
Shouldn't the size for iPhone5 be:(640*1136) and for iPhone4: (640*960)
I am new to Unity IOS development. If anyone can help me understand the concept, I would be very thankful.
I think when running in the editor you get the actual width and height of the game view window, scaled to fit the aspect ratio you have chosen. So, in iPhone5(9:16) mode, your window is 361 pixels high, so, to give you a 9:16 aspect ratio you need 203 pixel width. If your game window is 1136 pixels tall, then you'll get a width of 640, which I think is what you want.
To follow up on the comment by Graham...
Set your target platform to iOS. Then you can pick the correct iOS screen size in the "Aspect Dropdown" of the game view.
https://docs.unity3d.com/Documentation/$$anonymous$$anual/PublishingBuilds.html
https://docs.unity3d.com/Documentation/$$anonymous$$anual/GameView40.html
By the way, Graham. How do I @ reference you? Your name has a space in it and if I type @Graham Dunnett it points to some other guy.
This stumped me a bit too, but it does make some sense, because the viewport size is based on the PC's game window when you're viewing it. However, it would be nice to have a "lock to specific resolution" feature that would make the game window lock to the proper resolution. I just manually enforced this by resizing the game window to the proper height as a floating window, and then you can test your code properly.
Your answer
Follow this Question
Related Questions
Windows publishing wrong screensize?! 2 Answers
Set Game View Resolution 1 Answer
Box Collider 2D Not Scaling Correctly On Different Devices 1 Answer
Auto Scale camera depending on Screen Size - How?? 3 Answers
GUI Label Text Sizing problem 1 Answer