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;
}
}
}
Comment
Answer by JedBeryll · May 30, 2016 at 06:29 PM
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.
Your answer
Follow this Question
Related Questions
When playing builded version of game the cameras only captures part of scene. 0 Answers
CS1216 error 0 Answers
Rotate towards mouse pointer 1 Answer
Keeping player within screenbounds with moving camera (Vertical Shooter) 2 Answers
Screen Resolution 0 Answers