- Home /
Activate and Deactivate Animations With a Button Press
Hi
I have a variety of animations which I wish to play with a button press
I want a 'jet pack' animation to play and then a 'hover' animation on a button press and then a 'deactivate jet pack' animation on the same button press.
This is the script I have so far:
var activated = false;
function Update() { if (Input.GetButton("jetpack")) { activated = !activated; if (activated) animation.Crossfade("jetpackActivate"); else animation.CrossFade("jetpackDe-activate") } }
However, it seems to be a little sketchy and doesn't always work!
Any help would be amazing!
Thank You
You may want to edit your question to format that code sample. You can select all of the code and press the "101010" button.
Also, what's not working? $$anonymous$$ore specific questions tend to get more specific answers.
Answer by BrotherB · Mar 29, 2012 at 02:45 AM
Off the top of my head, I think you could put the code which activates and deactivates the jetpack in its own function, called from the key press under Update, so you can put a slight delay on it with yield, or some other way. This is so you have time to let off the button so the variable doesn't immediately flip back. I've run into what I think might be similar problems and this solved it.
Your answer
![](https://koobas.hobune.stream/wayback/20220613065641im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Animation / Distance 0 Answers
how to get a animation from other script on colision 1 Answer
How to call animation from another Script in C#? 1 Answer
Animation problems 1 Answer
How to click a 3d object in unity3d? 3 Answers