5
\$\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

2 Answers 2

4
\$\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\$
0
\$\begingroup\$

I tried @Almo solution but actually it didn't work in all the cases:

It was ok with aspect ratio 2:1 First image




It was ok with aspect ratio 4:1 Second image




It was not ok with aspect ratio 1:2. As you can see below, the green rectangles on the corners are different, compared to the ones in the previous images. Third image

So I looked for a new solution and I came across this script from the asset store. Note that, if you need to use it for Canvas, you must switch from Screen Space - Overlay to Screen Space - Camera. Thanks to that asset, the game can have the same aspect ratio at all cost. It still works in Unity 6000.2.6f2.

\$\endgroup\$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.