- Home /
Change window size without changing game resolution?
I'm trying to keep a low game resolution as well as prevent scaling of rendered objects on the screen. My reason for this is mainly keeping the correct pixels-per-unit for meshes displayed while being window size independent.
If you have played any Chris Sawyer game, the UI and rendered scene resemble this behavior.
Window Size 1
Window Size 2
The black/red boxes represent GUI elements and the blue iso-cube represents a mesh. The resolution of the two are the same but the second has an obviously larger screen. The player has a larger view of what is happening but there is no unwanted scaling.
How would I go about implementing this in Unity with an isometric camera? Is this math I have to do on my part in code, or are there some means already in place for achieving this behavior?
Answer by Teravisor · Feb 07, 2016 at 10:01 PM
For isometric view:
If you're using orthographic camera, I suggest saving
float proportion = camera.orthographicSize / Mathf.Min(Screen.width, Screen.height);and then modify camera.orthographicSize so it saves same proportion when screen was resized
camera.orthographicSize = proportion * Mathf.Min(Screen.width, Screen.height);
There is, unfortunately, one thing I think is unfixable: during resize it will be scaled for a little time because camera's view is still scaled and Unity script only affects it on next frame.
For UI: I recommend using anchors. You can set them in RectTransform component of UI element. They tell system where base point is relative to screen size (for X 0 is left side of screen, 1 is right side of screen; for Y 0 is bottom, 1 is top). And then setting offset of UI elements for them to be in place you want.
Answer by Dibbie · Feb 07, 2016 at 10:01 PM
You may want to look into UI Anchoring (http://docs.unity3d.com/Manual/UIBasicLayout.html)
basically, that point in the middle of the UI (by default) is what affects how that element will look on different resolutions.
This video is also pretty helpful: https://youtu.be/svyDgYz5idg?t=507
Your answer
