O'Reilly logo

Learning Unity 2D Game Development by Example by Venita Pereira

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Movement controls

Now that we have our hero character's animations ready, we can detect input from the player in order to control the hero's movement.

We will play the animation that corresponds with the direction that the hero is moving. We will use the W, A, S, and D keys on our keyboard as our movement keys.

Before we can detect input in script and then output the corresponding animation, we first need to set the states and order the transitions between multiple animations using the Animator.

Movement Controls Animator

We assign the Animator component to the hero GameObject within the Inspector by going to Add Component | Miscellaneous | Animator. Then, within the Animator View (you can open this by going to Window | Animator), order the animation ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required