How to make game work on ALL screen sizes?

Hello!

I have been developing a simple 2D game, and worked so hard at it. Was pretty proud until I realized that it wouldn’t scale the game to smaller screen sizes. However, the canvas elements (text) move to the edges of any screen size. This is hard to explain, please look at the pictures here: Imgur: The magic of the Internet

As you can see, on the large screen size, all the objects and UI elements show, but when I make a smaller screen, the object sizes remain the same, meaning that much of the game isn’t visible. Also, notice how the “score” stays on the left, but the top-right “hamburger” button doesn’t?

So question: How to make the game scale to any screen size? THANKS!

I think in you screenshots the canvas is working fine, But the rest of the things are not working correctly like the Rocket, BG, fuel size.
As per my observation these object should scale according to the screen resolution …
I generally used the approach like make all the Sprite Renderer (2D elements) to the child of one major parent. and then scale the parent according to Screen height & width.
( the above approach is not for Canvas)

Note :- Kindly check the output in any resolution expect in ‘Free Aspect’.

Attached script should be on the parent of all the BG or the elements which you want to scale

using UnityEngine;
using System.Collections;

public class ScaleForDevice : MonoBehaviour {

	public float resoulutionFactor ;
	float _height = Screen.height;
	float _weight = Screen.width;
	float scaleFactorW;
	float scaleFactorH;
	void Awake () {

				float _height = Screen.height;
				float _weight = Screen.width;
				float scaleFactorW = _weight / 1024; //1136
				float scaleFactorH = _height / 768;
		resoulutionFactor = scaleFactorW / scaleFactorH;

#if UNITY_IOS

	if(iPhone.generation == iPhoneGeneration.iPhone4 || iPhone.generation == iPhoneGeneration.iPhone4S) 
		{
		if (scaleFactorW > scaleFactorH) {						
			this.transform.localScale = new Vector3 (scaleFactorW / scaleFactorH, 1, 1);
		}
	}
#endif
		#if UNITY_ANDROID  || UNITY_EDITOR

		if (scaleFactorW > scaleFactorH) {						
		this.transform.localScale = new Vector3 (scaleFactorW / scaleFactorH, 1, scaleFactorW / scaleFactorH);
		}
#endif
}
}

The above code may vary sometime, we might have to handle it some time.

@itsharshdeep Thanks so much! The script worked to make the canvas elements fit, and also the objects get smaller as the screen gets smaller.

However, my scripts that move the player (the rocket) still make it move off-screen. Also, the instantiation script (to spawn objects that fall from above)makes the objects go off-screen. How to make the sizes in scripts screen-based? For example, here is my player controller script:

using UnityEngine;
using System.Collections;

[System.Serializable]
public class Done_Boundary 
{
	public float xMin, xMax, zMin, zMax;
}

public class Done_PlayerController : MonoBehaviour
{
	public float speed;
	public float tilt;
	public Done_Boundary boundary;

	
	
	void Update ()

        {
            transform.Translate(Input.acceleration.x / 3, 0, 0);
        }
    void Start ()

    {
		GetComponent<Rigidbody>().velocity = transform.right * speed;
    }

void FixedUpdate ()
	{
		float moveHorizontal = Input.GetAxis ("Horizontal");
		float moveVertical = Input.GetAxis ("Vertical");

		Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
		GetComponent<Rigidbody>().velocity = movement * speed;
		
		GetComponent<Rigidbody>().position = new Vector3
		(
			Mathf.Clamp (GetComponent<Rigidbody>().position.x, boundary.xMin, boundary.xMax), 
			0.0f, 
			Mathf.Clamp (GetComponent<Rigidbody>().position.z, boundary.zMin, boundary.zMax)
		);
		
		GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, 0.0f, GetComponent<Rigidbody>().velocity.x * -tilt);
	}
}