How do I make my 2D game responsive to different resolutions?

Viewed 377

I making a 2D game in unity. And I want to make my game responsive to different resolutions, and when I use Canvas Scaler all my UI objects become very bigger.

if you can help please response.

thank you!

1 Answers

Designing UI for Multiple Resolutions

1. Using anchors to adapt to different aspect ratios

One way to keep buttons inside the screen is to anchor them to their respective corners,

Rect Transform

One way to keep the buttons inside the screen is to change the layout such that the locations of the buttons are tied to their respective corners of the screen.

Once the buttons have been anchored to their respective corners, they stick to them when changing the resolution to a different aspect ratio.

When the screen size is changed to a larger or smaller resolution, the buttons will also remain anchored to their respective corners. However, since they keep their original size as specified in pixels, they may take up a larger or smaller proportion of the screen.

2. Scaling with Screen Size

In the Canvas Scaler component, you can set its UI Scale Mode to Scale With Screen Size. With this scale mode you can specify a resolution to use as reference. If the current screen resolution is smaller or larger than this reference resolution, the scale factor of the Canvas is set accordingly, so all the UI elements are scaled up or down together with the screen resolution.

Canvas Scaler

The layouts will appear the same in different resolutions, only with a lower pixel density depending on if you scale up or down.

One thing to be aware of: It can be possible that some element are larger in landscape aspect ratio. This can be fixed if you change the Match property to 0.5 instead, it will compare both the current width to the reference width and the current height to the reference height now.

Unity Documentation

Related