Hi!
In my FPS project I’m trying to make door open by clicking on them and with a sound and I almoust done it, but I have last one problem. I would like to make, that function OnMouseDown () will be activ only when “Player” gets close to my door. I taged my FPS Controler as a “Player” and I have done animation of a open/close door in Unity3d. And when I’m trying to run preview there is this error in 8th line (if): NullReferenceException: Object reference not set to an instance of an object
this is my Java script:
public var dist:int = 2;
var target : GameObject;
var animation1 : AnimationClip;
var sound1 : AudioClip;
function OnMouseDown () {
if(Vector3.Distance(GameObject.Find("Player").position, transform.position) <= dist)
audio.clip = sound1;
audio.Play ();
target.animation.clip = animation1;
target.animation.Play ();
}
function Update () {
}
please help!
what am I doing wrong?
thx