In this article, we are going to add an attack animation to our player using a Trigger parameter to make the transition from Idle to Attack. We will need to be able to meet the transition condition of the Trigger by communicating between the Player and Player Animation script.
We start by creating a Trigger parameter called Attack, which will cause the Transition from Idle to Attack.
A Trigger will make the transition when it is called and once the Attack animation is done playing it will automatically transition back to the Idle animation.
In the Player Animation script we simply create a public method, Attack, that will set the Attack trigger in the animator.
Over in the Player script, we want to call the Attack method from Player Animation script when the left mouse if clicked and the player is grounded.
You can see the animator transitions from Idle to Attack when the Player is grounded and left mouse button is clicked, but not when the player is jumping.
We will be adding a running and jumpinng attack.