- Home /
How to open a door with the "E" key
I have a door that is animated. The door opens from frames 1 to 32, then closes the door at frames 36 to 56.
From my understanding you are able to stop the animation at a certain frame, then start it again when you press your key.
I want to be able to press "E" and the door opens. The animations stops at frame 32. Then press "E" again to close the door. (Start animation at 36 and stop it at 56. Once you close the door. I want to be able to press "E" again and the animation starts again at frame 1.
I have the door rigged and imported into unity. The door is named "Door1".
I am not a programmer. I am an animator and do not know javascript well. If someone could point me in the right direction that would help out tremendously.
I have figured out how to make multiple takes in Unity! I have Take1 (1-32) and Take2 (36-56)
Now I need to figure out how to press "E" and open the door. I just want to make sure it plays in the order of Take1, then Take2, and reset back to Take1.
Please if it's not a complete answer on your question post it in the comments.
Answer by Bolbo13 · Jun 01, 2014 at 07:02 PM
you need to go to your update function and do something like this :
void Update()
{
if(Input.GetKeyDown(KeyCode.E))
{
if(isDoorOpen)
//call your door opening animation
//set isDoorOpen to true
else
//call your door closing animation
//set isDoorOpen to false
}
}
Basically that's the idea.
If you want it for javascript, remember to make it Function Update() ins$$anonymous$$d of Void.
Awesome thanks! I figured it out using somewhat of a similar method and it worked out perfect.
Your answer
Follow this Question
Related Questions
Raycasting fail 1 Answer
on mouse over and at a distance 2 Answers
Door Opening And Closing 2 Answers
Opening an animated door with a keycard 0 Answers
Canceling animation.Play functions after being used 1 Answer