The script below is attached to any object that I want to interact with (later on) what is meant to happen is that when the camera/FPC is a certain distance away from the object with the cursor on it, the colour should revert back to the normal colour when its not on any object, but I keep getting NullReference and I know it has to do with the variable cam but i’m just not sure what to do.
var gamePointer : GameObject;
private var cam : GameObject;
var triggerDistance : float = 7.0;
function Start() {
cam = GameObject.Find(“Main Camera”);
}
function OnMouseEnter () {
print (DistanceFromCamera());
if (DistanceFromCamera() > triggerDistance) return;
gamePointer.SendMessage(“CursorColorChange”, true);
}
function OnMouseExit(){
gamePointer.SendMessage(“CursorColorChange”, false);
}
function DistanceFromCamera() {
var heading : Vector3 = transform.position - cam.tranform.position;
var distance : float = Vector3.Dot(heading, cam.transform.forward);
return distance;
}
If anyone can help me I’d be really grateful.