4
\$\begingroup\$

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.

\$\endgroup\$
1

1 Answer 1

3
\$\begingroup\$

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.

enter image description here

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.

enter image description here

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.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .