2D Mobile Game

Objective: Add attack animation to our player

First of all create an animation clip by selecting the player sprite and drop-down animations > Create new clip. Then drag all the attack animation sprites.

After that is done, create a trigger that will then start the animation when set to active.

Then make transitions to the other animations that can transition to attack mainly run, walk and idle. Create a condition to enable the attack animation when trigger is active and keep the transition from the attack to idle empty so that after the animation is complete, the player will go to idle.

Now create a new function inside the player animation script which will set the trigger active.

Then inside the update in player script, create a condition where if the player is on ground(isJumping=true) and if the left mouse button is pressed, then the attack bool is set to true to disable movement and then player attack animation is triggered and finally coroutine is called to enable movement again.

This IEnumerator will wait till the end of the animation before setting the attacking to false.

And with this, the movement is enabled after the attack is complete.

And this is the final result.

Unity Developer