So I just found out about a bug in my game. If I press a button to attack, and then immediately press the button to duck (which will play a different animation), then the ‘DoDamage’ event from the attack animation will still fire.
Why is this, and how can I stop it? I had assumed that a new animation would interrupt the previous one, but apparently not as the events from the previous animation are still firing.
I found a workaround (see below) by enabling / disabling the animator, but I’m really hoping for a better way.
Some more information: I start attack animations in code, and all animations are set to transition to idle afterwards. Oh, and I’m not using mechanim.
I’ve been doing some fiddling around: This will not start an attack animation, and go straight to ducking. No event fired:
animator.Play(attackanimation);
animator.Play(duckanimation);
This will start an attack animation, then immediately do a ducking animation - but the attack events are still fired:
animator.Play(attackanimation);
yieldreturnnewWaitForEndOfFrame();
animator.Play(duckanimation);
This will start the attack animation, then immediately do a ducking animation - no attack events are fired.
animator.Play(attackanimation)
yieldreturnnewWaitForEndOfFrame();
animator.enabled =false;
yieldreturnnewWaitForEndOfFrame();
animator.enabled =true;
animator.Play(duckanimation);