- Home /
Script error help!
Hi!
I was wondering why I get these errors from my script:
Script:
#pragma strict
private var X : float;
var offset : int;
var FollowCamera : boolean;
function Start ()
{
X = Camera.main.transform.position.x;
}
function Update ()
{
if(FollowCamera)
{
transform.position.x = (Camera.main.transform.position.x - X)/offset;
} else {
transform.position.x = (X - Camera.main.transform.position.x - X)/offset;
}
}
Answer by Landern · Nov 22, 2013 at 03:59 PM
It appears that Camera.main is returning null, X will initialize to 0 and it's not nullable. Make sure your camera is tagged "MainCamera", also you can try replacing Camera.main.transform.position.x with Camera.current.transform.position.x, current get the current rendering camera, main will return a tagged camera tagged with "MainCamera".
It worked when I tagged the camera "$$anonymous$$ainCamera". Thanks!
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Selecting Object From Top Causes NullReference 1 Answer
"Strange behaviour may occur" when using Network.AllocateViewID() 0 Answers
UNEXPECTED TOKEN ) PLEASE HELP ME ;( 1 Answer
Nested Functions 1 Answer