- Home /
Animation stuck if i hold the trigger Button
Hi, i have an animation that starts when my bool is true which happens when i press the button V, it works like it should but if i hold in the button V it gets stuck in this animation and wont return to idle so the bool stays as true even when i release the button.
if (Input.GetKey (KeyCode.V) && !anim.GetBool ("Attack")) {
anim.SetBool ("Attack", true);
i have an animation event that turns it back to false at the last frame.
void StopAttack()
{
anim.SetBool ("Attack", false);
}
The problem accures when i happen to press the Trigger button the exact second as the Attack animation is supposed to go back to idle.
Answer by Dave-Carlile · Jun 26, 2015 at 05:35 PM
GetKey returns true as long as the key is held down, so you're always resetting your bool
to true. You want GetKeyDown, which returns true only once until the key is released and pressed again.
but this forces me to hold down the key to play the whole animation doesn't it?
No. Your Attack bool should stay true until the animation is over? Unless you're calling StopAttack somewhere you're not showing in your code.
I tried with Get$$anonymous$$eyDown, same result, it gets stuck if i happen the press the $$anonymous$$eyCode on the last frame.