Mobile Games In Unity: Attack Animation Set Up

This article will be super short. You know how to make animations with 2D Sprites and you know how to set parameters in code. I’m going to quickly set up a player attack animation using a trigger paramter.

All I do is make the animation and set the transitions in the animator to the attack trigger without exit time.

Now all thats left to do is set this using our Player Class and our PlayerAnimation Class.

In the PlayerAnimation class, I have a helper method called public void AnimAttack() where I simply set the attack trigger.

In the player class I decided to make a new method called “Attack()” and simply say if left click happens, call th epublic helper method in the PlayerAnimation class.

Once thats done, I simply call this method in Update(). Since theres an if statement within this mehtod, it wont be called unless the conditions of the if statement are met :). Be sure to set the attack to running transition condition to if Move is greater than 0.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store