On the bottom left corner of the “Animator” view, you can find a parameters list. The gray states are the normal ones, holding zero or one animation. With this state machine, any state can transition to a “Jump” state. However, if you add a few more states, you will need to create a lot of transitions to “Jump” from every state. Great, we are now able to “Jump” from the “Walk” and “Run” states. It’s not ideal, is it? We should be able to “Jump” when we “Walk” too! If you never “Run”, you will never “Jump”. It means that the “Jump” animation won’t be played unless your object is in the “Run” state before. In order to “Jump”, you have to “Walk” first, then “Run” and FINALLY “Jump”. In our “Boss” state machine, this state is, at the same time, the “Idle”, the “Hit” and the “Attack” states. It represents (as its name says so well) any state at a given time. It’s a good way to simplify a state machine. The green state, called “Any State”, is a special case. That means that when the game is started, the “Boss” object will automatically play the “Idle” animation (indefinitely if “Loop Time” is enabled in the animation “Inspector” - as it should be for this tutorial). In this case, the “Idle” state is the default one (if it’s not, right click and “Set As Default”). The orange state is the default one: the initial state when the game is launched. For now, let’s look at the three different types of states. We will focus a bit more on transitions in a moment.
In order to animate the object with the “Hit” animation, we have to be in the “Idle” state first. In this image, we have created a link between two states. Each state can be an animation, and you can define transitions between them.Ī transition tells to Unity when and why it should move from a state to another. Remember when you used the “Create New Clip” button of the “Animation” view ? Unity was in fact adding a state in the controller of the object, linked to the animation file you had created.Ĭlick on each state of the animator and rename them to remove the “Boss_” prefix:Īn “Animator Controller” is a state machine.
2d animation unity plus#
You can see that we have some states (the rectangles) created automatically with our clips, plus a special one called “Any State”. You can double click on the controller file (“Animations/Boss”) to open the controller, or you can find it in the “Window” menu: Inside an animatorĪs it was not confusing enough, we need to open the window called “Animator” (and not “Animation” this time). Yet, it doesn’t matter here because we have a very simple object with no gravity. The “Apply Root Motion” should probably be disabled when using the animations the way we do in this tutorial. Options: the “Animator” component has some other options.