- Home /
Question by
Whoohoobar · Apr 24, 2013 at 10:54 PM ·
animationswalking
I made a walking animation for my sword, how do I trigger it with a button?
when I press play, my walking animation where the sword bobs around back and forth works correctly, but it constantly loops, I want to make it so it's still when I'm standing, but I want to trigger the animation for when I press W to move, anyone know how to do that?
Comment
Answer by Z2CSharp · Apr 25, 2013 at 01:42 AM
private bool Idle = false;
private float Speed = 0;
void Update()
{
if(Speed < 10.0f)
{
Idle = true; // Make Idle true to trigger the Idle animation
}
if(Idle == true)
{
animation.Play ("Sword_Idle"); // Play Idle animation when Speed is less than 10 (AKA 0)
}
if(Input.GetKey (KeyCode.W))
{
animation.Play("Sword_Walking"); // Play walking animation when we are holding W
Speed = 10.0f; // Change speed so we can move
}
}
This should work (P.S this is C#, I can't code in Java)
Your answer
Follow this Question
Related Questions
Idle and Walk animation don't work at all 1 Answer
How To Mirror Animation 1 Answer
Enemy walking above ground 1 Answer
Animations for combos and more. 0 Answers
Setting up animator 1 Answer