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:

I dont know if thats what you're talking about but i was designing UI with this method: http://answers.unity3d.com/questions/756158/pixel-unit-to-scale-unit.html

–

well i also want a border in my game which will always fit perfectly to my screen. in my current project everything is cut of because it is too long or too short.

–

2 Answers

2

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.

i have done this now, but everything is sooo small that i nearly can't see it. which value do i need to set the near and far value at the camera ? Edit: when i divide by 250 the size is better but why do i have to do this ? Edit2: when i try it on a phone with a lower resolution everything is too big.

–

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;
}