- Home /
Two Animations With One Button Press
Hi!
What I am trying to achieve is being able to press one button to activate/deactivate an animation.
I have two animations, a jetpack activate and a jetpack de-activate.
All I want to do is trigger each animation with one button press :D
I'm not really sure how I could go about doing this :/
I have been using:
animation.CrossFade("jetpackActivate") animation.CrossFade("jetpackDe-activate")
Thank you in advance :D
Did you want Activate to play until finished, them play Deactivate? Or press key once to activate, then again to deactivate?
I wanted to press key once to activate, then again to deactivate :D
Answer by DaveA · Mar 26, 2012 at 11:01 PM
 var activated = false;
 
 function Update()
 {
   if (Input.GetButton("jetpack"))
   {
    activated = !activated;
    if (activated)
      animation.Crossfade("jetpackActivate");
    else
      animation.CrossFade("jetpackDe-activate")
   }
 }
Set up 'jetpack' in the Input Manager (Edit/Project Settings/Input)
This has worked!
However, I also have an idle animation playing when the character is still and that seems to make the character not stay in the air when the jet pack is activated.
I tried animation.Stop("idle") within the script you wrote above, but nothing happened :/
Any ideas?
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                