Important Notice:

As of September 15, 2016, we no longer publish new courses on this website. We encourage you to use your Digital-Tutors credentials to sign in on Pluralsight where you'll find all new creative courses, skill tests and paths, 1:1 mentoring and more.
Setting up the animations
See Details
Joshua Kinney


Joshua Kinney
In this lesson, we're going to set up our animations in Mecanim. All right, so first thing that you want to do is go ahead and open up the Animator window here, and you could go to Window, and then simply click on Animator. And what I did is I went ahead and docked the Animation tab in with the scene and game, and then brought animator down where animation was before. So here you can see that automatically we have our animation clips inside of the animator. And what it does is it just recognizes these two animation clips, and places those in there. Now what we can do is if I select my character, and if I hit Play, I already have the idle animation tied to this character. It is the default. Because we have the animator component and the controller set up, those animations have been tied to this controller. Now, what's happening right now is that the character is only playing the idle animation. As you can see, this is going back and forth, it's looping through. What happens if I want press a key on the keyboard, and I want him to go into the walk animation. Well, what I would need to do is create a transition that goes from idle to walk, and then from walk back to idle. So if I'm pressing the key, it's going to transition to the walk, and then continue to walk until I release the key, and then it's going to transition back to idle, and then start playing the idle animation again. So we're just creating a loop here. So this is pretty simple to do. Let's go ahead and turn, or hit Play and turn that off. And what I'm going to do is I'm going to select my idle. I'm going to right-click, and I'm going to make a transition. And then I'm going to left-click on the animation clip that I want to make a transition to, so in this case, walk. Then we're going to left-click on the walk, right-click, make transition, and left-click on idle. So now we have these two transitions. Another thing that I want to do is I want to go ahead and create a parameter, because I want to be able to control this. So click on the Plus sign here, to add a parameter to our list. And we're going to make a float parameter. And we're going to make this pretty standard, we're going to call this speed. You could call it whatever you want, for movement, or whatever you want to do exactly. I'm going to go ahead and hit Enter on that, and we've created a value called speed. And so speed, whenever it's equal to zero, we're going to be at idle. So if we're greater than zero, I want to be moving into the walk. And so, with this, we're going to left-click on that transition, and we're going to scroll down here, and you can see that is transitioning from idle to walk. And what I want to do is I want to say speed is greater than zero. So if we're pressing whatever key, and making our speed value go up, if it's greater than, it's going to go into the walk. Now, if speed is equal to zero, and actually, let's see, let's say if speed is less than zero. Actually let's do, not zero, let's do 0.1. Actually let's do 0.01. Make that a small number. And let's make this one greater than 0.01 as well. So if we're at zero, which is a good number, we're going to be idling. If we're less than, or greater than, or if we're greater than zero, if we're walking, or if we're moving, we're going to go in to the walk. Once we've released that, and that condition says, OK, we're less than 0.01, meaning we're going back to zero, we're going to go back to the idle. That works just fine. All right, so now that that is set up, now what we need to do is we need to go ahead and code this. We need to tie a value to that speed variable. And we're not going to get real in-depth with this. We'll create a script to get ourselves moving. And so we're going to go ahead and start fresh in the next lesson, and we'll get started with that.
In this series of training we will discuss the major components of working with the 2D features in Unity. We'll start off by learning how to set up a 2D Unity project. Then we'll learn how to properly import and slice our sprites. After that we'll learn how to manipulate sprites by blocking in a simple platform level and also learn the importance of Sorting Layers.

Then we'll jump into the real fun by assembling, parenting and animating a character. By the end of this tutorial, you will have a better understanding of working with Unity's 2D features.