|
I have a trigger that plays a door animation when i step on it but when i step out of the trigger and back in the animation plays again. I want it so that i go into the trigger and the door opens and stays open. Heres the script:
var dooropenandclose : AnimationClip; //this is your animation clip.
var Celldooropensound : AudioClip;
var door : GameObject; //this is your game object that you want to move on trigger.
function OnTriggerEnter(){
animation.Play ("dooropenandclose");
audio.PlayOneShot(Celldooropensound);
}
(comments are locked)
|
|
Use a boolean variable as a flag to indicate if the door is closed, and only open it if this flag is true:
var dooropenandclose : AnimationClip; //this is your animation clip.
var Celldooropensound : AudioClip;
var door : GameObject; //this is your game object that you want to move on trigger.
private var closed = true; // door initially closed
function OnTriggerEnter(){
if (closed){ // only do it if door closed
closed = false; // door now is open
animation.Play ("dooropenandclose");
audio.PlayOneShot(Celldooropensound);
}
}
Thanks man! works well!
Sep 08 '11 at 01:13 AM
zacwashere2011
Yeah just wanted to say, thanks a bunch, this was uuber helpful in a general sense just to get a grasp on what can be done with private variables and basic if/thens. Feel like I"m "gettting" conditionals now!
Apr 19 '12 at 07:12 AM
bayerly
(comments are locked)
|
