Unity on mobile cuts off sides (not canvas related), on different resolutions

Viewed 129

I'm developing a 3d game on unity and using the 1080x1920 portrait resolution.

When I build and run the project on my phone, which has a 1080x2340 resolution in portrait, it cuts off part of the game (the sides).

red lines indicating where it cuts off

The camera doesn't follow, so the player can "go out of the screen".

How can I fix this, making sure my game looks the same on different resolutions?

(edited to correct resolution order)

1 Answers

Does your play area have a fixed size? If the in-game play area's aspect ratio isn't the same as the device running the game, you'll have to either cut off part of it or include blank space at the top/bottom or left/right. Unity's camera orthographic size dictates how tall the camera view is, but not how wide. The width is just screenAspectRatio * camera orthographic size.

To fix this:

float aspect = Screen.Width / Screen.Height;
myCamera.orthographicSize = Mathf.Max(playAreaHeight, playAreaWidth / aspect);

This will cause the camera's view to be either too wide or too tall rather than too small.

Related