Welcome back, My favorite game developers.
In this video, we are going to be making the layer,
I mean the boss take damage.
So when we run the game that's put on Skelly scroll down.
You can see right now that he has
a max boss health and a bus current health.
So I should him once you'll notice he becomes four.
Why does he become four?
I mean, why does he become angry?
Because halfway through his help,
we are going to make him angry.
So when his health as
halfway he gets angry. We shoot him again.
We should infer the last time.
As you can see, he dies and he disappears and the end.
So let's not waste any more time and Let's get started.
Oh, case.
So time to add a BRAF health to our boss.
So let's go ahead and get started.
The first thing that we are going to do
is go from angry walking to dying.
And we are going to go ahead and
create a trigger in here called a die,
and set the conditions in here to die.
And then we are going to scroll down.
And in here where we are walking to get angry,
we're going to add a condition and set it as
the get angry trigger 0 case.
So with that out of the way,
I think that's all that we had
to set up before we get started.
So I'm going to go inside of the boss script folder and
right-click and create a new C Sharp script
called the boss health handler.
Hit Enter, wait for it to compile.
And we'll drag it into these Kelly boss.
Why are we doing it in here?
Well, because dying is or the boss
health handler or the entire health
is part of the whole boss.
It's not specified to a single state, just like we said,
it's for the whole boss
and it's going to be pretty simple.
First of all, in here,
I'm going to create a serialized field,
which is going to be an integer and the boss,
max health, and it's going to be equal to 500.
And then we are going to create a public current health.
And obviously we will change that later on.
So boss, current health, save that.
And then, and start.
We're just going to say that the bosses current health is
equal to the bosses max health.
Correct?
So now we need to create a method to allow
us to give damage to our boss.
So for that, I'm going to show it to you as
a challenge because we've already done this.
So make the boss take damage.
First of all, you need to create
the variable quality max health and the current health.
Obviously, I did not prepare properly because
I thought that you should have done this on your own.
But there you go.
An extra step from me either for you.
Let's continue on and starts at
the current health extra smart move by me,
then create a method that allows
the boss take damage based on a parameter.
Finally, something new for you to do.
When health is half the max health,
we need to transition into the dying animation.
Oops, I say dying.
I meant to say,
wait for the magic of editing.
Hey, you Welcome back.
So create a method that
allows the boss to take damage when
health is have the max health transition
into the angry animation.
So you know what to do when the heart is at 0,
transition to the dying animation and finally
destroy them both using an event system.
So with all of that information,
pause the video right now.
Don't make any mistakes like me.
And go ahead and do the challenge.
Okay, welcome back.
How did you get on with that?
So in here I'm going to create a public void.
The damage was an integer,
the amount of damage.
This is all pretty basic.
I believe you already know how to do everything.
So in here I'm going to say,
I'm going to say that the bosses current health is
minus equal the amount of damage.
Then I'm going to say if the bosses current
health as less than or equal to,
less than or equal to the max boss health,
bus, max health divided by two.
So this means we are halfway into his health.
Then we are going to get component, the animator.
And he may talk.
Thank you. And we are going to set the trigger.
And we are going to get angry.
So let's go into our animator and let's
copy the get angry back in here.
Paste it right here.
There we go. So now we get angry.
And then we are going to go ahead and say,
if the boss current health is less than or equal to 0,
then we are going to go ahead and do the same in here,
but instead of getting angry,
we are going to die.
Excellent.
So dy, so now we are going to create a method to die.
So in here I'm going to say void,
destroy, destroy the boss.
And we are simply going to go ahead and
destroy the game object.
And where should we be calling this?
Let's make this one public,
just in case so we can access it from the event system.
Whereas the event system,
if I click on these,
Kelly, we go to the animations, we die.
What do we have in here?
Let's see, in the scenes, there we go.
So we, we have this puddle of ABA,
no bone blood or something.
And we should make this one a bit red obviously.
And maybe at this point,
just keep it a couple of seconds.
And then we are going to add an event system.
Or maybe we know what. Let's Move it to second two.
And in here, we destroy the boss.
So in the animation,
we die and then we destroy the boss.
Excellent, save all of that.
Let's see what else do we have?
Oh, so obviously we need to
also trigger that take damage.
Where do we call the trip take damage?
Well, if we go into the layer, have bullet.
If I open this up and find the player,
then I say Player health bullet.
I meant the player bullet controller. In here.
We are going to check if we have the enemy,
then we are going to damage the enemy.
Let's see, do we have a layer for the boss?
We don't have a lawyer for the boss,
so let's go ahead and edit the layers.
Create a boss layer,
or you can create a boss tag.
That's also something we can do.
Or maybe we do have a boss tag note
we don't have Abel's dark,
so let's go ahead and edit.
Create a tags.
Boss DAG.
There we go. So now if we go in here, so now,
now this is the perfect example for you to
understand the difference between a tag and a layer.
So remember where.
Okay, So I don't even remember
maybe in the spikes in here,
I told you that we can avoid
using the compare tag player.
We can immediately say that spikes
are some kind of damage layer,
so they are on the Do we have anything,
the pickups or anythings,
for example, the backups.
So we can avoid using
the a tag to compare it to the player,
for example, to make sure that only the layer carries it.
So only the player can
interact with the pickups through layers.
We don't need to check for
a compared tag on the entrepreneur.
Enter. Remember I talked about this,
but now in the a bullet controller,
we can say that the bullet only interact with the boss,
but that is not enough
because we want to also check else.
If there is a collision.com tag with a boss,
then we need to call
a totally different component
or totally different yes, component.
So back in here,
let's see, is the syllabus.
Oh, we didn't create the tag sorting layer.
No, no. Why do we have to sorting layers for the boss?
The tag is so boss. Copy that.
So now we have no sorry,
we need to set the boss tag.
There we go. We save that.
Now back in our game,
we check for the boss.
And if it is the boss,
then we are going to go ahead and get
the collision that get component,
the boss health handler.
And from here we are going to take damage and
it's going to be the bullet speed.
Nope, the damage amount.
So damage amount, save that.
Now we have everything set up,
so I'm really happy that this came up.
This is a way for you to demonstrate.
We could have said that the we have a bullet layer,
a player bullet layer,
and it only interacts with the boss and the enemy.
But if we hit an enemy,
the boss isn't just any enemy.
He is also a boss health handler.
So we'll need to access the health and the boss.
If we tried to use this one, it will not work.
It will cause an error so well
that although the way save that,
you can also go ahead and copy
these two lines and we can set them in here.
So obviously this is redundant code.
So what we can do is
right-click and here quick actions and
refactoring and we can say create blood effect,
extract the method, call it instantiate blood effect.
And I write instantiate correctly is Dan Shi Da.
Yep, there we go.
Apply the changes and in here we are going to
instantiate the blood effect. Save that.
So now back in,
our game shouldn't be working perfectly.
So if I click on this caliber,
scroll down and the boss Mac South, Let's make it 20.
Uh, no, no, not 20, maybe 40,
just so we can see the transitions
properly. We run the game.
So now the boss comes up.
We shoot him once, and I don't want to
maximize on play on again.
Who should the boss? Where Z?
So we should the boss.
Let's scroll down.
What is his health current health wise, the books.
So such a new bullet.
And okay, so this error is nothing also
because the crystal has some kind of damage.
Okay, so I'm going to make this four instead of 40.
Know what, Let's make it eight. Run the game.
The system is very poor,
so we should at once,
there we go, we scroll down,
it's at six. We should, uh, twice.
There we go. We can see that he gets
angry and now he starts running much faster.
So we shoot him again.
We should him for the last time. And there we go.
He goes into the bottle and he dies.
But there is something a bit wrong but I did not,
like you might have not seen it because I didn't do it.
But when we shoot him once,
shoot him twice, he is getting angry.
I can still shoot him.
And there you go. You can see that he still gets
shot and dies immediately
after he transitions to the walking.
So in the next video,
we are going to make sure that he is
invincible while he is getting angry.
And just for the sake of remembering,
I'm going to add a comment in here and make,
you know what, let's immediately right.
If getting angry, this should not work.
And this is just a demonstration of how
sometimes you might want to add something in the future,
just so you don't forget it.
Add a comment, make sure it works.
I hope you enjoyed.
This was a really nice video it thought as
the important lesson of
the difference between tags and layers,
because sometimes it's hard to explain,
but this was the perfect place to learn it.
So I hope you enjoy it.
I hope you are committing your changes and
I'll see you in the next one.