- Home /
2D Orthographic matching proportions to screen resolution
Hello,
Im creating a 2D Game with an Orthographic camera setup. I have problems with the proportions, for example I have screen resolution 1280x768 Orthographic Cam Size 5. When I create a plane - which size must it have to exactly fill the screen? Thanks in advance :) Ebil
Answer by robertbu · Jan 26, 2014 at 02:40 AM
Orthographic size is 1/2 of the size seen by the camera vertically, and the horizontal size will be based on the aspect ratio. So you want to make your plane:
var y : float = Camera.main.orthographicSize * 2.0;
var x : float = y * Screen.width / Screen.height;
transform.localScale = Vector3(x, y, 1);
This will be the size for Unity's Quad. For a Plane, divide the size by 10 since Unity's built-in plane is 10 x 10 with a local scale of (1,1,1).
Thanks a lot for that. This is great to set scene backgrounds to resolutions - notably main menu. Just a quick note - make sure you don't declare Y and X outside of your main thread (e.g. not in start or other function) if not you get a main thread error. So to be safe this (I'm dividing by 10 as I have a plane):
var y : float;
var x : float;
function Start()
{
y = Camera.main.orthographicSize * 2.0;
x = y * Screen.width / Screen.height;
transform.localScale = Vector3(x/10, y/10, 1);
}
or that
function Start()
{
var y = Camera.main.orthographicSize * 2.0;
var x = y * Screen.width / Screen.height;
transform.localScale = Vector3(x/10, y/10, 1);
}