How to resize camera to work with multiple resolutions on Unity?

Viewed 125

I'm working on a fun project on Unity and I want to support all mobile resolutions in landscape mode. I designed everything to work in 1920:1080 resolution.

Everything works in world space, including UI elements.

What's correct way of supporting all resolutions (including weird ones like square 1:1)?

I don't want the scene to be cropped or filled with blue, all I want is my camera's viewport to be scaled to fit the device screen. I don't care if objects in the scene will get thin or fat.

1 Answers

To support different aspect ratios for your UI Elements, I recommend making use of the anchors that come with every RectTransform. These will ensure that the position of an element is consistent across various aspect ratios. For example, setting the anchor of an element to be left on the x axis will make the origin and pivot on the far left. This means an x position of 10 will position the element 10 units away from the far left of the element's parent. This is made easier with Anchor Presets. Although you can set every value yourself, Anchor Presets provide an easier way to anchor your UI Elements. Provided you have a RectTransform on you UI Elements, every element should have the Anchor Presets available. No need to change the width and height of your Canvas.

Aside from that the Camera should automatically resize depending on the resolution of the game view. You can test how your elements' anchoring works with different aspect resolutions by setting your game view's Aspect to free aspect, which will change the aspect ratio of the game depending on game view's width and height.

Related