- Home /
Door Opens Automatically, then it stays open forever. How?
I am using the script(javascript) below to make the door open when the player enters the trigger. It works, but when I reenter the trigger area, the animation starts again, and it is weird to see the door starting the animation again. Therefore, i would like to leave the door open forever. Should I kill the script? I can't kill the gameobject.
Thanks in advance!
var MovingWall : AnimationClip;
function OnTriggerEnter (player : Collider) {
if(player.tag=="Player")
GameObject.Find("MovingWall").animation.Play("MovingWall");
}
function OnTriggerExit (player : Collider) {
if(player.tag=="Player")
GameObject.Find("MovingWall").animation.Stop("MovingWall");
}
Answer by kacyesp · Sep 02, 2014 at 10:33 PM
Use a boolean to not play the animation if the door is open.
private bool doorIsOpen = false;
function OnTriggerEnter (player : Collider) {
if ( doorIsOpen )
return;
if( player.compareTag("Player") ) {
GameObject.Find("MovingWall").animation.Play("MovingWall");
doorIsOpen = true;
}
}
Answer by nielisson · Sep 03, 2014 at 10:43 AM
Thanks for the help, kacyesp. But I didn't work. There is a compiler error. I replaced my old script to the one you wrote above.
Your answer

Follow this Question
Related Questions
Can someone help me fix my Javascript for Flickering Light? 6 Answers
I cant get my animation to trigger. 0 Answers
How to get OnTriggerEnter to react to only something with a specific name. 1 Answer
OnTriggerEnter only recognised once, no matter how many times I enter ? (Solved) 1 Answer
HELP PLEASE! 3 Answers