I'd like my game to have the same aspect ratio at all cost, including keeping all UI elements fixed in the same place. I'm totally ok with losing screen space in the interest of fixing the aspect ratio.
1 Answer
First, attach a Canvas Scaler
component to the GameObject
with your Canvas
on it. Set it to Scale With Screen Size
. Set the resolution you want your game to mimic. I have 640x1136 set. Set Screen Match Mode
to Expand
.
Inside this GameObject
, create a new one. In my scene, it's called "GameSizingPanel". You can see it just has a CanvasRenderer
and an Aspect Ratio Fitter
. Divide the width by the height that you set in the outer object. In my case, 640 / 1136 is 0.56338. Set this number in the Aspect Ratio
slot. Set the Aspect Mode
to Fit In Parent
.
Attach all of your game objects to be displayed under the object with the Aspect Ratio Fitter
in it.
If you'd like to see what the results are like, you can download the (free) finished product on iOS or Android. It's called "Cognizer". There's also a web version at my website, which you can find in my profile.