- Home /
Open Door Via Trigger Collider
What am I doing wrong here?
I have a DoorController which has a trigger collider on it, when the player walks into that collider, the DoorController should then tell the door to open, and then close on exit. But it doesn't ... what am I doing wrong?
DoorController:
private var doorOpen : boolean = false; var doorObject : GameObject;
function OnTriggerEnter (door : Collider) { if(door.collider.gameObject.tag == "Player"){ doorObject.animation["LabDoor"].speed = 1.0; doorObject.animation.Play("LabDoor"); doorOpen = true; }
}
function OnTriggerExit (door : Collider){ if(doorOpen == true){ doorObject.animation["LabDoor"].time = doorObject.animation["LabDoor"].length; doorObject.animation["LabDoor"].speed = -1.0; doorObject.animation.Play("LabDoor"); //yield WaitForSeconds(1); doorOpen = false; } }
All that happens is this:
I walk up to door, it opens. As I continue to walk through it closes (this is all good) - but when I come to walk up to it again, it does not open, and then when I exit the collider it plays the close door animation!
Please help, thanks!
Have you tried a Debug.Log on your boolean to be sure it's switching properly?