- Home /
How to check how many times an animation has played?
I'm working on a script for a turn-based combat system. This is the part where, when the player attacks, an attacking animation should play:
IEnumerator PlayerAttack()
{
playerUnit.GetComponent<Animator>().SetBool("attacking", true); // The attacking animation will play
playerUnit.GetComponent<Animator>().SetBool("attacking", false); // Stops the attacking animation
}
attacking is a Boolean parameter; the animation should play if attacking is true. In this case I want it to play once before stopping (i.e. changing attacking back to being false). However, the animation doesn't seem to play at all. How can I check how many times the animation has played?
Answer by Llama_w_2Ls · Aug 26, 2020 at 02:35 PM
You can add an event to the end of your animation clip that can run a function from any public void within your scrupts. You can make it run a void that adds one and updates a counter every time the animation reaches the end, which should tell you how many times the animation has played.