Make unity camera appear all screen width

Hi all,
When you design on unity (for android), it don’t care about the screen width. It show any thing appear on the screen height of camera. But I want it base on the screen width, not screen height.I want to show anything that appear on the screen width of camera. Any solution for it. Thanks.

For this you need to define what width you want your world to be (Let’s say 800 units long). After that you need to get the current aspect ratio of the camera. Calculate the camera height based on the world width and aspect ratio of the camera, then apply to the orthographic size.

float aspectRatio = (float)Screen.width / (float)Screen.height;
float cameraHeight = WORLD_WIDTH / aspectRatio;

camera.orthographicSize = cameraHeight/2f;

The reason we use half the desired camera height for the orthographicSize is because that’s what the orthographicSize actually is:

orthographicSize

This should leave everything centered and lock the camera to your world width while different devices show more or less vertical height. If you want your camera to always be at the bottom of the level you’ll need to adjust the camera’s vertical position.

Hope this helps.