Scale Everything In Game to Fit all screen Sizes

I have checked online both on for the answers to this question but have only found vague responses, i would be so grateful if someone could help me out with this.

I am creating a small game, and am near completion, i used the Unity build settings to build the game but then came across a problem. the game was designed in the 16:10 aspect ratio as it suits my monitor, but anytime i build the game on a smaller resolution parts of the game get cut off from the screen. I intended to release this game for android and obviously need something that allows the game to fit on any size screen or tablet.

the GUI scales fine due to the option to make the canvas ‘scale with screen size’ im looking for the same for everything else in the game.

additional info:

I have an orthographic camera

I have been told in other forums that i need Camera.main.aspect = ScreenWidth / ScreenHeight;

but in my script this doesnt do anything.

I have included my camera script as well:


public class CameraScript : MonoBehaviour {

public Transform PlayerTarget;

public float YaXis;
public float XaXis;
public float moveDown;
public float moveUp;

public Vector2 
	margin, 
	Smoothing;

private Vector3 
	_min, 
	_max,
	PlayerPosition;


public bool IsFollowing;

public BoxCollider2D CamBounds;

public void Start()
{


	//float worldScreenHeight = Camera.main.orthographicSize * 2f;
	//float worldScreenWidth = worldScreenHeight / Screen.height * Screen.width;

	//Camera.main.aspect = worldScreenWidth / worldScreenHeight;

	_min = CamBounds.bounds.min;
	_max = CamBounds.bounds.max;
	IsFollowing = true;
	
}

public void Update()
{
	var x = transform.position.x;
	var y = transform.position.y;
	
	if (IsFollowing) 
	{
		if (Mathf.Abs(x - PlayerTarget.position.x)> margin.x)
			x = Mathf.Lerp (x, PlayerTarget.position.x, Smoothing.x * Time.deltaTime);
		
		if (Mathf.Abs(y - PlayerTarget.position.y)> margin.y)
			y = Mathf.Lerp (y, PlayerTarget.position.y, Smoothing.y * Time.deltaTime);
	}

	var CameraHalfWidth = GetComponent<Camera>().orthographicSize * ((float)Screen.width / Screen.height);

	x = Mathf.Clamp (x, _min.x + CameraHalfWidth, _max.x - CameraHalfWidth);
	y = Mathf.Clamp (y, _min.y + GetComponent<Camera>().orthographicSize, _max.y - GetComponent<Camera>().orthographicSize);

	if (Input.GetKey(KeyCode.DownArrow)){
		transform.position = new Vector3 ((x - XaXis) , (y + YaXis) - moveDown, transform.position.z);
	}else if (Input.GetKey(KeyCode.UpArrow)){
		transform.position = new Vector3 ((x - XaXis) , (y + YaXis) + moveUp, transform.position.z);
	}else
	transform.position = new Vector3 ((x - XaXis) , (y + YaXis), transform.position.z);

}

}

You can force a screen ratio in your game. If someone is using a different ratio, they will see black bars on the top and bottom or sides to meet the ratio you defined…

Screen.SetResolution