- Home /
How to control an animation with both GetButton and GetButtonDown
Hello, I have an attack animation that I want to trigger in too different ways:
I want to trigger it with just a click (Using
Input.GetButtonDown()
launching a trigger "attack")I want to trigger it continuously when holding the mouse ( Using
Input.GetButton()
)
The problem is that when I click and release slowly, the animation is triggered twice (If I release quickly, the animation plays just once).
I tried using animator.GetCurrentAnimatorStateInfo(0).IsName("Attack")
to see if the animation is still on or not, but I get the same result, two attack animations.
So my question is, how should I proceed?
I found a solution already :
if (Input.GetButton("Attack"))
_animator.SetTrigger("attacking");
if (Input.GetButtonUp("Attack"))
_animator.ResetTrigger("attacking");
That way, when the mouse is not pressed, the animation won't play.
Your answer
![](https://koobas.hobune.stream/wayback/20220612071933im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
[SOLVED]How to set the animator's controller in an editor script? 0 Answers
Bug animation transitions, or am I the bug? 0 Answers
trouble with run animations 1 Answer
What's the best practice for setting up different character animations for different weapons? 0 Answers
IK Targets are not working 1 Answer