- Home /
Keep screen width instead of height for resolutions
Hello I am new to Unity, but so far I ve managed to google solutions to my problems until this one.
When changing resolution in 2D project or let say aspect ratio, unity will keep my screen height and scale my width.
But I want it vice versa Here are some images:
At the sedond image,there is cropped a part of path in grey area HoW do I make it to cropp from top of the screen and keep the same width"? THanks
I don't post this as an answer, because I havent tested it very well, but I think this might push you in the right direction.
You'll want to change the camera's orthographicSize). You want it to have a value like 5 (can be anything you want) for instance on your target aspect ratio (height/width of screen)
As an easy example, you have everything set up for a resolution of 300x300 (aspect ratio of 1 as this makes further calculations simpler) on which you use 5 as orthographic size.
And you want to display it on 300x600 (aspect ratio of 0.5)
You should set your camera's orthographicSize to: 5 / aspect. So in case of 300x600 this would be (5 / 0.5 = 10)
Now if your original target aspect is not 1, you'll have to offset the aspect so that your target aspect is inserted as 1 in above calculations. But as I said, havent tested this enough to give you the exact maths ;)
Answer by RadonRaph · Jan 06, 2019 at 01:18 PM
The result in game's window and in the build its not the same, try to build to see if the problem persist. Also you can look at: https://docs.unity3d.com/ScriptReference/Screen.SetResolution.html https://docs.unity3d.com/ScriptReference/Screen-height.html https://docs.unity3d.com/ScriptReference/Screen-width.html
Good day, Raph