C# orthographic scripting error. Please help.

List item

Alight, so here is the old script:

using UnityEngine; using System.Collections;

public class PixelPerfectCamera : MonoBehaviour {

 public static float pixelsToUnits = 1f;
 public static float scale = 1f;
 public Vector2 nativeResolution = new Vector2 (240, 160);
 void Awake () {
     var camera = GetComponent<Camera> ();
     if (camera.orthographic) {
         scale = Screen.height / nativeResolution.y;
         pixelsToUnits *= scale;
         camera.orthographicSize = (Screen.height / 2.0f / pixelsToUnits);
     }
 }

And here is the new script. The only problem is that I can’t get the new script to run. It keeps pulling up an error. Can someone please help me?

using UnityEngine; using System.Collections;

public class PixelPerfectCamera : MonoBehaviour {

 public static float pixelsToUnits = 1f;
 public static float scale = 1f;
 public Vector2 nativeResolution = new Vector2 (240, 160);
 void Awake () {
     var camera = GetComponent<Camera> ();
     if (camera.orthographic) {
         scale = Screen.height / nativeResolution.y;
         pixelsToUnits *= scale;
 camera.orthographicSize = Screen.height / 2.0f / scale
 camera.orthographicSize = Screen.height / 2.0f / (Screen.height / nativeResolution.y)
 camera.orthographicSize = 1 / 2.0f / ( 1/nativeResolution.y)
 camera.orthographicSize = nativeResolution.y / 2.0f 
 camera.orthographicSize = 160 / 2.0f  = 80;
}
}
}

1 Answer

1

Well many lines are missing a semicolon at the end so you should take care of those and see if there are any real errors.

  camera.orthographicSize = Screen.height / 2.0f / scale
  camera.orthographicSize = Screen.height / 2.0f / (Screen.height / nativeResolution.y)
  camera.orthographicSize = 1 / 2.0f / ( 1/nativeResolution.y)
  camera.orthographicSize = nativeResolution.y / 2.0f

Thank you. I am so burnt and can't believe I did that. I will resubmit if there are more "real" errors.