Hi!
I can’t understand why I get this.
This is an open/close door script, with a timer to close the door.
The script is working. I can play the game, but when I get to this door,
the door will open, but after 3 sec. the door will shut automatically, then I get this error.
NullReferenceException
PlayerCollisions.ShutDoor (UnityEngine.GameObject door) (at Assets/Scripts/PlayerCollisions.js:38)
PlayerCollisions.Update () (at Assets/Scripts/PlayerCollisions.js:18)
The error line is at the bottom with this line “door.audio.PlayOneShot(doorShutSound);”
I would be very grateful if someone can try to help me with this.
#pragma strict
private var doorIsOpen : boolean = false;
private var doorTimer : float = 0.0;
private var currentDoor : GameObject;
var doorOpenTime : float = 3.0;
var doorOpenSound : AudioClip;
var doorShutSound : AudioClip;
function Start () {
}
function Update () {
if(doorIsOpen) {
doorTimer += Time.deltaTime;
if(doorTimer > doorOpenTime){
ShutDoor(currentDoor);
doorTimer = 0.0f;
}
}
}
function OnControllerColliderHit (Hit : ControllerColliderHit){
if(Hit.gameObject.tag == "playerDoor" doorIsOpen == false){
OpenDoor(Hit.gameObject);
}
}
function OpenDoor(door : GameObject){
doorIsOpen = true;
door.audio.PlayOneShot(doorOpenSound);
door.transform.parent.animation.Play("dooropen");
}
function ShutDoor(door : GameObject){
doorIsOpen = false;
door.audio.PlayOneShot(doorShutSound);
door.transform.parent.animation.Play("doorshut");
}