- Home /
Door Opening And Closing
Hello, I have been trying to solve this problem i've had with opening and closing doors. It works perfectly besides after you open then close it, once you hit "F" to open again it doesn't work.
The script is down below
var DoorStatus : boolean = true;
function OnTriggerStay (myTrigger : Collider) {
if(myTrigger.gameObject.name == "First Person Controller" ){
if(Input.GetKeyDown ("f"))
if(DoorStatus){
animation.Play();
animation.wrapMode = WrapMode.ClampForever;
DoorStatus = false;
}
}
if(myTrigger.gameObject.name == "First Person Controller"){
if(Input.GetKeyDown ("g"))
if(!DoorStatus)
animation.Play("Door Animation Close");
animation.wrapMode = WrapMode.ClampForever;
}
}
Answer by Polinator · Mar 06, 2013 at 11:10 PM
like robertbu stated, you need to make DoorStatus = true again. I think you also need brackets enclosing the DoorStatus statement so that it doesn't go true every time you hit g, only when it closes. Also I guess the if statement for input on "G" would require one too, but maybe not if it worked for your "F" key.
if(myTrigger.gameObject.name == "First Person Controller"){
if(Input.GetKeyDown ("g")){
if(!DoorStatus){
animation.Play("Door Animation Close");
animation.wrapMode = WrapMode.ClampForever;
DoorStatus = true;
}
}
}
No problem. Brackets used to never be my friend, but then I started using them for every statement, even if it's just one line haha.
Answer by robertbu · Mar 06, 2013 at 10:33 PM
You need to set DoorStatus back to true. Put on line 18:
DoorStatus = true;
I tried this and it still didn't work. The door wouldn't close when I hit "G". I also tried on line 19 to add return;
Nothing worked.
Your answer
Follow this Question
Related Questions
Simple Script - and no result 2 Answers
open and close a door with a keypress 6 Answers
Script for a door that opens and closes help! 1 Answer
Closing sliding door Raycasting 1 Answer