Different camera views in different devices


In my editor I made game with resolution 1280 x 800. I made camera to fill this stage.

That how it looks in my editor:

But when I build *.apk file and installed it into phone with small screen it will look like that:

So it does not show all the stage.

But then I have installed it into device with big screen (Galaxy Note 2). It shows me not only stage with white background but also takes parts that are redundant to player:


Question: What kind of script code I must to write(in C#) to make it look like in editor, when I run it on every device?

I given answer for your solution in this link.

link text

just create and apply script on main camera.

I hope this will help you out. Add this script to main camera. You can recalculate the ratio if you want.

using UnityEngine;
using System.Collections;

public class FixedRatio : MonoBehaviour {

    // Use this for initialization
    void Start () 
	    // set the desired aspect ratio (the values in this example are
	    // hard-coded for 16:9, but you could make them into public
	    // variables instead so you can set them at design time)
	    float targetaspect = 1280.0f / 800.0f;
	    // determine the game window's current aspect ratio
	    float windowaspect = (float)Screen.width / (float)Screen.height;
	    // current viewport height should be scaled by this amount
	    float scaleheight = windowaspect / targetaspect;
	    // obtain camera component so we can modify its viewport
	    Camera camera = GetComponent<Camera>();
	    // if scaled height is less than current height, add letterbox
	    if (scaleheight < 1.0f)
		    Rect rect = camera.rect;
		    rect.width = 1.0f;
		    rect.height = scaleheight;
		    rect.x = 0;
		    rect.y = (1.0f - scaleheight) / 2.0f;
		    camera.rect = rect;
	    else // add pillarbox
		    float scalewidth = 1.0f / scaleheight;
		    Rect rect = camera.rect;
		    rect.width = scalewidth;
		    rect.height = 1.0f;
		    rect.x = (1.0f - scalewidth) / 2.0f;
		    rect.y = 0;
		    camera.rect = rect;

I would recommend using a plugin such as NGUI for your UI. NGUI uses something called anchoring, which can (for example) anchor your object to the top right corner, so they always stay there, no matter the resolution.

For other tricks, I’d recommend creating a background around your game that repeats itself (in case of orientations that are too wide/too high). I use this for a platform runner, where the width is always the same, but based on the aspect ratio, the player sees less/more sky.

I have added such script implemetation to my game but I still have 1 problem. Because of the images resize, the canvas resize doesnt fit the real game screen. See pictures as example:

Before playing I force free aspect and the canvas resize to fill the full size of the real screen

Then I press play and the game resize with the camera script but the canvas remains the same

¿Who can alfo fix this?
Thank you