We also need to play the heart animation clip.
So once this enemy one GameObject takes damage, it's need to play the heart animation clip.
So if you if we select our enemy one GameObject in the hierarchy, then move over to animator tab.
So we need to trigger this heart parameter.
And we do know that if we trigger it, it's gonna play the heart animation clip.
So before we do scripting let me show you.
So let's click on this play button in the top to play our game.
And if we trigger this heart parameter manually, as soon as we're gonna trigger it, this enemy one
just gonna play the heart animation right away.
And after playing that, it's gonna move over to this arrow fire or a idle animation clip, depending
upon where player is.
If the player is inside attack range, then it's gonna play the arrow fire right away.
And if it's not, then it's gonna play the idle one.
So now if I select my enemy one in the hierarchy, then move over to animator tab and then try to trigger
this heart parameter manually.
We can see it's playing the heart animation clip as soon as we're triggering.
So instead of doing manually, we're going to do it once this anime one game object takes damage.
So let's get out of play mode, and let's open up the anime one script by double clicking on it.
And we do know that we need a reference of this animator component, and we have it already.
So what we're going to do now, we're going to move over to that line, that line of code, or in a
function where we just are taking damage.
So we're taking damage right over here.
As you can see, we're just subtracting from our max health this damage amount.
So after taking damage we also need to play that animation clip.
So we will go to our animator component.
So let's go to animator component Animator.
And we're going to use this start trigger function a set trigger.
And this function in brackets.
It's going to take uh the parameter name inside in quotation inside this brackets.
And the parameter name is hurt.
And make sure you spell it correct.
And after that close that off with semicolon.
And we're going to press down Ctrl s one more time in order to save our script.
And now let's move over.
Move over to unity.
So as soon as, as soon as we're gonna start taking damage from this, uh, player game object, we
will able to notice this enemy one gonna play the heart animation clip.
And after playing that, it's gonna move over to idle or arrow fire, depending upon where player is.
If the player is in attack range, then it's gonna shoot out the Ray.
Sorry.
It's gonna attack on this player game object.
Our enemy.
One game object.
Just gonna damage our player game object.
So let's have a look on this.
So just wait a little moment, and once it's done, we're gonna able to see that.
So just wait a little moment.
It's gonna take few second and after few second it's gonna be done.
So now as you can see, it's done.
And if we just go ahead and then click on this play button in the top in order to play our game.
And then if we start, uh, Damaging our enemy one.
Then this enemy one just gonna play the heart animation clip.
And after that, it's gonna play the arrow, fire or idol, depending upon where player is.
So let's get closer to this enemy one game object first.
So I'm gonna get closer to this enemy one.
And if I damage it, we can see this enemy one playing that damage animation clip.
And once it's, uh, loses all of his health, then it just playing the diet, and after five seconds,
it just get destroyed itself.
So I'm gonna get out of play mode, and I'm gonna give some more health to this enemy one game object
in order to check that heart animation clip.
So I'm gonna select my enemy one GameObject in the hierarchy.
Let's go over to Inspector, then enemy one script and the Maxhealth.
I'm gonna make this one something around 50 in order to check it.
You do not make it 50.
You can make it less as much as you can for testing purposes.
I'm just, uh, doing it with 50.
So let's begin with this.
So I'm gonna click on this start uh button.
Sorry play button in the top so we can play our game and let's have a look on it.
So as soon as we just gonna damage our enemy one, it's gonna play the heart animation clip.
So let's do that first.
Firstly, we need to get closer to this enemy one game object.
So let's damage it.
Now we can see it's playing the heart animation clip.
And right after it it's playing the arrow fire.
Because this player inside attack range.
So that's why.
And we can see.
And after playing the heart animation clip it's playing the arrow fire.
Because we are in you can simply say in attack range.
And if we just go far away from this enemy one game object, then we can notice it's playing the idle
animation clip over again and again.
So I hope you get the idea that how you can do it.
So we also need to do something in order to make this one cool, like camera shaking and as well as
a floating text just gonna pop up once this animated enemy one game object takes damage.
So I'm gonna get out of play mode.
So I hope you get the idea that how you can do it.