I’m trying to achieve this:
iphone5
ipad
The problem is that when the resolution changes, it is locking the height and expanding the width to the new ratio.
I have seen this solution:
float aspectRatio = (float)Screen.width / (float)Screen.height;
float cameraHeight = WORLD_WIDTH / aspectRatio;
camera.orthographicSize = cameraHeight/2f;
The problem with Screen.width does not work in the Editor. It gives me the size of the entire editor window and has nothing to do with the resolution set in the game window.
I would like to be able to preview what the game will look like at different resolutions and not just hope things look fine on all devices.
Oddly, the CanvasScaler can already do this. Does anyone know a way to achieve this so that I can preview different resolutions in the editor? Is there a way to get the world
this is what I ended up with:
int cameraHeight = 178;
int fixedWidth = 1136;
float desiredAspect = 16f/9f;
float aspect = Camera.main.aspect;
float ratio = desiredAspect / aspect;
Camera.main.orthographicSize = cameraHeight * ratio;
cameraHeight was just the height that I happened to be working in. Seems very hacky. Is there a better way?