- Home /
Duplicate Question
Door script not completely working help!
hey there. my script here is really annoying me because when ever i put it on a door and the tags and that are working but it keeps on looping only the (!stat) and i can't get it to switch to (stat). it would be greatly appreciated if someone could help fix this script, thanks
public var stat : boolean;
public var able : boolean;
var open : AudioClip;
var clos : AudioClip;
function Awake () {
if(stat){
animation.Play("openstat");
}
}
function OnTriggerEnter( other : Collider ) {
if(other.tag == ("Player")){
able = true;
}
}
function OnTriggerExit( other : Collider ) {
if(other.tag == ("Player")){
able = false;
}
}
function Update () {
if(able){
if(stat){
if(Input.GetKeyDown("e")){
stat = false;
animation.Play("closingdoor", PlayMode.StopAll);
audio.PlayOneShot(clos);
Debug.LogWarning("im now closed");
}
}
if(!stat){
if(Input.GetKeyDown("e")){
stat = true;
animation.Play("openingdoor", PlayMode.StopAll);
audio.PlayOneShot(open);
Debug.LogWarning("im now open");
}
}
}
}
Answer by robertbu · May 25, 2013 at 06:38 AM
One issue (perhaps 'the' issue) is that you need an 'else' on line 54. Right now if the 'e' key is pressed, you do the 'if (stat)' block which sets 'stat' to 'false' which means that the 'if (!stat) block will also be executed in the same frame.
Follow this Question
Related Questions
My animation keeps on repeating on my animator 1 Answer
GameObject reacts to audio source 1 Answer
Mecanim Boolean 1 Answer
Open door as Character approaches 2 Answers
Sliding door animation question. 3 Answers