- Home /
How can i play the animation on every mouse click (if the aimation is already running i have to play the animation one more time)
public void callThrow() {
Debug.Log ("Screen touched "+j++);
if((ninja_Forward.GetCurrentAnimatorStateInfo(0).IsName("Ninja_idle"))||
(ninja_Forward.GetCurrentAnimatorStateInfo(0).IsName("Throw_forward")))
{
ninja_Forward.Play("Throw_forward");
}
} the above function has to execute on every mouse click.. if i pressed two times means it has to play the animation two times .. but its executing only once even for 3 clicks.. how can i make the animation to play based on mouse click count..
Answer by allenallenallen · Jan 02, 2016 at 08:46 AM
Use a counter to count how many times the user has clicked. Each time the animation starts, subtract one from the counter.
You can constantly check if the animation is playing using: http://docs.unity3d.com/ScriptReference/Animation.IsPlaying.html
When it's not playing and counter is greater than zero, play the animation again.
Your answer
![](https://koobas.hobune.stream/wayback/20220612054645im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Simple Animation Question (Resetting animation) 0 Answers
Animate two properties independently,How to animate two properties independently? 0 Answers
Duplicating animation clip keyframe behaviour in multiple clips 0 Answers
Is it possible to change the size of text in the animator window? 1 Answer
Is there a way to access the current animation clip being edited through a script? 1 Answer