-
In this video we're going to setup our
-
player animator controller so that
-
we can control what animation
-
is playing via a script.
-
The first thing that we're going to do is to add
-
the player prefab back to the hierarchy.
-
Let's go to Prefabs
-
select the player and drag to the hierarchy.
-
Next we're going to open our player animator controller.
-
Let's go to Animations
-
Animator Controllers
-
and double click Player.
-
Here we have the animations that we created
-
earlier which have been added to the animator
-
controller has states.
-
Let's lay these out so that we can see them a little more
-
clearly and we'll move the PlayerIdle up,
-
the PlayerChop will be over here and
-
the PlayerHit will be over here.
-
The PlayerIdle is orange because it's the default state.
-
So when the game starts playing
-
the player's idle animation is going to play.
-
What we're going to do is setup the transitions
-
when the PlayerIdle animation will stop playing and will
-
transition to either the Chop animation,
-
when the player attacks a wall,
-
or to the Hit animation when the player
-
is attacked by an enemy.
-
The first thing that we're going to want to do is setup
-
some parameters which are going to
-
be what we're going to use to trigger
-
those animations from our scripts.
-
You may need to click the Parameters button to
-
make the parameters visible,
-
and then we'll hit the + button
-
and add a parameter of the type trigger.
-
This first one is going to be called playerChop.
-
A trigger is like a boolean except it will
-
immediately be reset after it's used in a transition.
-
So it's a boolean that's going to remain true
-
for the frame in which it's called
-
and then become false again.
-
We're going to create another one called playerHit.
-
Next we want to create some transitions between our states.
-
Let's right click PlayerIdle,
-
select Make Transition,
-
and drag to our PlayerChop state.
-
We're then going to right click on PlayerChop
-
and make a transition back from
-
PlayerChop to PlayerIdle.
-
This means that PlayerIdle can transition
-
to PlayerChop and PlayerChop
-
can then transition back to PlayerIdle.
-
We'll click on the transition from PlayerIdle to
-
PlayerChop to make it visible in the inspector.
-
The transition from PlayerIdle to PlayerChop
-
is not going to have an exit time.
-
We're going to uncheck Has Exit Time.
-
What this means is that we're not going to wait
-
for the PlayerIdle animation to finish
-
or to reach any certain point before we can
-
transition to PlayerChop.
-
We're going to want the transition to happen
-
abruptly from PlayerIdle to PlayerChop
-
regardless of where we are in the Idle animation.
-
We're also going to open the settings and
-
set the transition duration to 0.
-
We're going to use a transition duration of 0
-
when we're working with sprite-based animation.
-
When we're working with 3D animation
-
it's common that we may want to blend
-
between animation states
-
but with sprite-based animation that's not possible
-
so we're going to want to immediately transition
-
from one state to another.
-
Next we're going to determine what is going
-
to cause this transition to happen.
-
In our list of conditions here we're going to click
-
the + button to add a new condition
-
which will determine when the transition
-
will be made.
-
A list of conditions will appear here,
-
in this case PlayerChop, which is the
-
default is actually the condition that we want.
-
If we wanted to change it we could choose from the list
-
and choose either PlayerChop or PlayerHit.
-
Now when the PlayerChop trigger is
-
set from our player script we'll
-
transition from PlayerIdle to PlayerChop.
-
For our transition from PlayerChop
-
back to PlayerIdle here we're going to keep
-
Has Exit Time active but we're going
-
to set it to 1, meaning that the PlayerChop
-
animation is going to need to be completely
-
finished before we're going to transition
-
back to PlayerIdle.
-
We're also going to set the transition duration here to 0.
-
Because we set Has Exit Time
-
to true from PlayerChop
-
to PlayerIdle we're not going to
-
need any additional conditions,
-
the transition will be made
-
when the exit time is reached.
-
Let's setup the same things for PlayerHit.
-
We'll select PlayerIdle,
-
choose Make Transition,
-
and drag to PlayerHit.
-
We'll click on PlayerHit, right click,
-
choose Make Transition,
-
and transition back to PlayerIdle.
-
We'll highlight the transition from PlayerIdle
-
to PlayerHit, and here we're going to set
-
Has Exit Time to false
-
because we want to interrupt the
-
PlayerIdle animation whenever the player is hit.
-
And we're going to set our transition duration again to 0.
-
In our list of conditions we're going to hit the + button,
-
and select PlayerHit from the drop down.
-
For our transition back to PlayerIdle.
-
We're going to use Has Exit Time because
-
we want the animation to finish playing
-
setting Exit Time to 1 because we want it to
-
transition at the end of the animation,
-
and we're going to set the transition duration to 0.
-
Before we move on we're going to give this a quick test.
-
Let's temporarily dock the animator window
-
down here on the bottom of the screen.
-
Play our game, and what we'll do
-
is we're going to manually fire the
-
triggers and see what happens.
-
First we'll try PlayerChop.
-
And then we'll try PlayerHit.
-
Excellent, so we can see that those are working.
-
Now that we've got our player animator controller working
-
we're going to move on in the next video
-
to writing the player script.