Scaling camera for Android

Hey everyone,

I am new to Unity and i try to make a 2D Game for Android devices.

The problem is that i do not know how to make my Game fitting for any Resolution.

Is there a way to scale the Camera so that it fits every screen resolution.

I will only have one MainCamera which will not move.

Thanks for you help !

It should look like this on my phone:

but it looks like this on my phone :frowning:

technically speaking in order to render properly on every screen you need 2 different things. first of all you need to set your Orthographic’s camera size to be adapted to the size of the device’s screen and secondly you need to rescale your assets to be adapted to your screen sizes.
as far as the camera concerns. so you need to set the size of the camera’s size to the half of the big side of your current resolution. example:

Camera.main.orthographicSize = Mathf.Max(Screen.width, Screen.height)/2;

do that once. Now you can rescale your items and position accordingly to the camera view to have your scene rendered properly in every resolution, this setup requires your pixel to units for all your sprites to be set to 1. if you want to set it to 100 for example you will need to devide the orthographicSize by 100.

Solved my problem by using this !

#pragma strict
 
private var baseAspect : float = 1280.0 / 800.0;
 
function Start() {
    var currAspect : float = 1.0 * Screen.width / Screen.height;
    Debug.Log(Camera.main.projectionMatrix);
    Debug.Log(baseAspect + ", " + currAspect + ", " + baseAspect / currAspect);
    Camera.main.projectionMatrix = Matrix4x4.Scale(Vector3(currAspect / baseAspect, 1.0, 1.0)) * Camera.main.projectionMatrix;
}