- Home /
make every player see the same picture with different aspect ratios?
I'm working on a 2D game right now, where it is very important that you have the same picture on your screen even with different screen ratios. Lately is stumbled upon the problem that Unity simply crops out everything that does not fit on the screen, so i tried to figure out a way to solve this problem. The free aspect of the camera is nearly 22 / 9, so the script simply compares the resolution of the script to this 22 / 9 ratio and makes the orthographic size of the camera bigger so everybody sees the same in width. The height varies though. Is that the only way or are there other and better ways out there to solve the problem?
float cameraratio = 22 / 9;
float screenwidth = Screen.width;
float screenheight = Screen.height;
float screenratio = screenwidth / screenheight;
float multiplier = cameraratio / screenratio;
camera.orthographicSize = camera.orthographicSize * multiplier;
Answer by elenzil · Apr 04, 2016 at 10:51 PM
look at the Canvas Scaler component on your UI Canvas.
I have no canvas' for now, but they wouldn't change with that script. With that it all stays the same (in width). Probably I don't get what you want to tell me.
Answer by Peysbubby · Apr 05, 2016 at 02:22 PM
I believe what @elenzil is trying to say is: you said this is a 2D game, the picture you are talking about should be an "image" on the canvas of a 2D game. Once you have this you could take a look at the Canvas Scaler component of the canvas to possibly get the desired affect you are looking for.
Please correct me if I'm wrong, but I believe this is what he was getting at.
ups, i think I used the wrong words. Let's say I have a stage with 2 different players on the same screen. Both should be visible all the time, but on the same time the stage has borders. With a small aspect ratio of 5:4 the vision is very small. To make that big enough I would need to make the stage huge so users with for example 16:9 do not see these borders. I want to find a way where the width of the viewport is always the same, no matter if it is on a 5:4 ratio, or a 16:9 ratio.
well, if you want to avoid stretching, you have to allow the camera to crop some stuff out. the canvas scalar component i and Peysbubby are suggesting has a setting which lets you either keep the screen width or the screen height a constant across different aspect ratios. google "unity canvas scaler". there's much discussion.
Your answer

Follow this Question
Related Questions
How to set mini map camera to display entirety of the map 2 Answers
How to make the camera show only the part of the world which is in a specified rectangle? 0 Answers
Calculate camera position when angle is change but viewport bottom need to be fixed? 0 Answers
2D camera zoom out by the distance of player to an object, Zoom in when it gets further away 0 Answers
When playing a scene, Render LOD lines are visible? 0 Answers