# In Unity, how do I set the window's size?

Say I want a "world map" (maybe think the overworld in ff games) with dimensions 800px by 600px. How would I do that? Is this tied in with the resolution? Because I know you can set the game aspect.

Tutorials don't seem to cover this. For example, in this video, he just sort of drops the sky into the scene. You can see that some parts of the sky is cut off. He fixes this later by setting the pixels to units to 200 instead of 100. However, this all seems arbitrary to me. We don't know how large the sky is now, ie we don't know the dimensions of the sky. How do people fix this problem? Do you just look at the original image and do math to figure out how "large" it is in unity? What happens if you do something like this video where no size is defined?

• Both links are to the same video. Was that intentional?
– Anko
Dec 14, 2015 at 17:12

It depends on your image.

If you have a background image that is say 1920 * 1080px in size, you just have to divide it by the "Pixels to Units" ratio to find out how big in units will the sprite be. So in this case, it'll be 19.2 * 10.8 units for the default 100 Pixels to Units ratio.

If I want the background's width in Unity to be 10 units, then I just need to divide my background's width by the required width. In this case it'll be 1920/10=192 which is the required Pixels to Units ratio for the background. Or if I want a height of 10 units then the ratio will be 1080/10=108.

Now if I know that my players will be playing in a 16:9 aspect ratio and I want my orthographic camera's viewport to have a width of 10 units, then the size of the camera (at least for me in Unity 5.0.1) has to be kept as 2.792129. That way you can modify the pixels to units ratio according to the image's height/width in pixels and the wanted height/width in Unity units respectively.

Simplest way to do this,

• Create a Quad. Make sure it has position (0,0,0) and scale (1,1,1)
• Keep selecting Quad, drop your Texture in inspector, that will create a new material.
• Set material's shader to Unlit/Texture or Unlit/Transparent (if your image has transparency)
• Create a small script named "ScaleToFit" or any other name you like,

using UnityEngine;
using System.Collections;

public class ScaleToFit: MonoBehaviour
{

float _screenWidth;
float _screenHeight;

void Start ()
{
_screenWidth = (Camera.main.orthographicSize * 2) / Screen.height * Screen.width;
_screenHeight = Camera.main.orthographicSize * 2;
transform.localScale = new Vector3(_screenWidth,_screenHeight);
}

// Update is called once per frame
void Update ()
{

}
}


Drop this script to the Quad. That's it. :)

There are two easy ways to do this :

1. Set the size of your image in Start() according to the screen size, by adding a simple
    this.transform.localScale.X = Screen.Width * pixelsToUnits;
this.transform.localScale.Y = Screen.Height * pixelsToUnits;

1. Use the image as a UI Image, instead of a gameObject, and make it Scale to fill the whole Canvas in the editor using its Rect Transform, which itself scales to the Screen Size.