Hello had a quick question,
I have a project I’m working on and I’m following a tutorial. The question is…
If I have a Camera and I change its size to fit the resolution of the device its on why must the number below be apart of a vector for it to remain the same number? Example-
public class PixlePerfectCamera : MonoBehaviour
{
public static float pixelsToUnits = 1f;
public static float scale = 1f;
Vector2 nativeResolution = new Vector2(240, 160); // see here how its 240 by 160
void Awake()
{
var camera = GetComponent();
if (camera.orthographic)
{
scale = Screen.height /nativeResolution.y;
pixelsToUnits *= scale;
camera.orthographicSize = (Screen.height / 2.0f) / pixelsToUnits;
}
so when I run this program I get the size of the camera to be 80.
but when I change the code a bit and remove the vector2 and just make a variable holding the value 160 I get a different result, like this.
public class PixlePerfectCamera : MonoBehaviour
{
public static float pixelsToUnits = 1f;
public static float scale = 1f;
int newSize = 160; // change here
void Awake()
{
var camera = GetComponent();
if (camera.orthographic)
{
scale = Screen.height /newSize; //change here
pixelsToUnits *= scale;
camera.orthographicSize = (Screen.height / 2.0f) / pixelsToUnits;
}
the new value of the camera is now 96? Why is that? I used the same number that was taken from the vector2 but it gave me a different number? Why is a vector 2 needed please explain. Thank you