From the course: Unity 5: 2D Building an Adventure Game

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Connect animations

Connect animations - Unity 2D Tutorial

From the course: Unity 5: 2D Building an Adventure Game

Start my 1-month free trial

Connect animations

- [Instructor] We're now ready to connect up the animations to our player in the game. Let's go ahead and open up the Player C# script. We're going to scroll up to the top, and we're going to create a new private field to store the reference to the game object's animator. We'll make this private, set it to a type, Animator, and we'll call this animator. Just like we did previously, let's set the value of the animator to the Animator component. Now that we have a reference to the animator, let's go ahead and wire up which animations we should show. The first thing we're going to want to do is set the animation for when we're walking. Inside of where we test for the controller.moving.x condition but below the condition where we test for the maximum velocity, let's go ahead and add our new animation. Here, we'll tell the animator to set an Integer, and we're going to call this Integer AnimState. You'll remember this name from when we set up our animations. We're going to set the value to…

Contents