Welcome back, My favorite game developers.
In this video, as you can see,
we've added a little image,
we've added a bit of text,
and we've added a big health bar
to represent the health of our boss.
So now when we run the game,
when the boss appears, we shoot him.
You can see that his life depletes.
When we shoot him again, he's angry.
And if we shoot him while he's angry,
you'll notice that he cannot take any damage.
And this is a mechanic of
every boss and every single game.
So I shoot him again, I showed him again,
the Health Bot disappears, the boss dies.
And let's not waste any more time with a very long video,
but leave me, it's important,
and this is what happens when we are creating your eyes.
So let's get started.
Okay, so now we have everything working kind of good.
We are able to damage the boss.
We are able to kill him,
we are able to remove him,
but we do not have any clue of where his health is add.
So what we're going to do is we're going to
create a helper for the boss.
So I'm going to go up in here.
And in this video actually,
I think there is something you can choose for yourself.
So there are two types of
health bars that you can add to the boss.
One of them will be, for example,
if you want the Health Bar to
always be moving with the boss.
But I personally think that is not the best idea because
you'd want to have
your regular enemies have
that health bar on top of their heads.
So maybe having a boss health bar
is better to be kind of like Dark Souls,
either be on the bottom or at the top.
And because we already have the health and the money
and the weapons on the bottom to display for the player.
Then I'm going to create it up here at the top.
So I'm going to open up the UI canvas.
I'm going to open up the health,
I'm going to get the health slider.
And the, we know what cuts
not used the health effects for the boss.
I'm going to duplicate it.
And I'm going to move it outside.
And I'll need to open
the prefabs and I'll need to move the, where is it?
Health, slider and outside right here.
Save that back into our game.
Now we have a health slider 1,
which is also an I by accident.
Remove the actual have slider yep. Open brief up.
So sorry for that.
Should have moved the other health slider.
So there we go. This one is in here.
And then I'm going to duplicate this one.
And I'm going to move this one outside of the canvas.
And the one that we have greater than here,
we can simply delete.
So where is the health slider?
There we go. This is the one that we need.
Let's see, move this up.
This will be the boss.
Have slider.
There we go. And I'm just going to go ahead and
maybe create an empty game object
right on here, set it outside.
So the boss slide,
I know this game object to the campus.
False health.
And then add the boss have slider under the boss health.
So this is very annoying whenever you have a prefab
by new want to change it, it's extremely annoying.
So even if I move this one,
I still need to change it right here.
So US health,
slider and then the UI canvas and empty game object,
which is the boss health.
Whereas the boss have.
And let's move the slider to the boss Health.
And let's set the position to be at 0,
0. And there we go.
So now we have the boss slider.
We are working in the prefab.
So in here I also want to make this a bit bigger.
So if I zoom in and let's see what we have in here.
Make this bigger on the side.
Make this bigger on the site.
Also.
Move it up a bit.
And I'm just going to go ahead.
And if you want,
you can go ahead and do it yourself.
Fill in everything.
Let's see all the little adjustments.
This will take a bit of fine
whenever you are, I think you are.
This is why the videos where we have you
are are longer than usual.
So there we go. I think this is good enough.
Yep, seems good to me.
And finally, I want to add a bit of an image.
So I'm going to go into UI image.
And this image will have the boss image.
And we can also add in here the boss name.
So I'm going to add a text Mesh probe.
And this will be Kelly.
Make it bold, make it in the middle.
Make it bold, make it a robotic.
And let's No, no, no.
And let's maybe move it.
You either under or over.
It doesn't matter. Choose your own way of creating this.
I'll make it auto size. And there we go.
So Kelly, there we go,
Skelly and here the image will represent the boss.
So I'm going to find in the sprites,
the z, whereas these candy bars, there we go.
So image, Skelly and native set to native size.
Let's preserve aspect ratio.
And let's make it look much, much smaller.
And maybe set it in here and know what,
maybe this is not the best way to do this.
Maybe you can just keep the head so you know what,
let me just delete
this or wait a second and I'm going to edit this photo.
Okay, welcome back.
So all that I did is just edit this photo and you'll
probably have it in your resources.
So I'm going to add it in here.
And the buses image will be the skeleton had.
So there we go. Now we have this.
I know this is not much,
it doesn't really make the game much better,
but it just adds a bit of finance.
So you know that this health bar belongs to
the Skelly boss and you have a small image of his head.
So now we have a good representation.
So now if I go back from the
prefab and for some reason it's not in its place.
We have the boss health.
Let's just delete this.
Keep this both health.
And for some reason it wasn't in its place.
I'm going to go Slider and set the position 0, 0.
And now we have it properly.
And let's adjust the position a bit. And there we go.
Now we have the boths.
Skelly health.
Let's just move it a bit to the left.
And I think it's pretty good right now.
So this is the help we can see on the boss if you want.
We can also change the image of the fill.
So I don't want it to be red.
Maybe I want it to have it in the sprites.
Let's see.
You have your eye.
You are you, are you I elements.
I was pressing the EU,
but I did not get that.
Okay, so I'm going to go into
the UI elements and get the blue one.
So we'll use the blue one.
Image.
The blue, no, no, no, no,
not this one. Fill area.
The fill the blue slider. Okay.
So now we have the blue slider moving up and down.
And as I've said, this whole section or this whole video,
you need to do your own research.
You need to create your own UI,
and you need to do things the way you would like
them to be.
Oh, okay.
So I think this is good enough.
I'm not sure if it is good enough.
And there is a bit of the edges are not very smooth,
but no worries about that as long as
it represents things properly.
So now we have the health.
The next thing we need to do is to have control over.
So I'm going to go into the bosses health,
I'm going to go into the script.
And in the UI or nano actually in the boss.
There we go.
Right-click create C-sharp script,
and this will be the boss Health Bar at Enter.
Wait for it to compile.
And any day now we have
the boss helpless add it to the boss health in
here that's opened up the boss Health Bar.
And what do we need to have in here?
Well, obviously we want a reference to the slider.
So serialized field slider,
we need to have a UI engine,
Unity engine dot u i.
So now we can have the slider,
then we have the boss health slider set then in here.
So the first thing we do as soon as we start as
we need to set the max value, obviously.
So the boss have
slider dot max value is equal to find objects of type.
And it's going to be the boss health handler.
And from the boss health handler,
we need to get the max health.
So we're going to go into the boss health handler.
And in here create a small method which
is going to be a public int.
Get max health, or get boss max health.
Open up the brackets, return Max, have.
We go save that. Back in here.
Get boss, max, health.
We save that.
Now we're going to slide into the Update,
get it slide because we are using
a slider or how often waiting on a slider.
So an update we are going to
all the time get the hub loss have
slider dot value and it's going
to be equal to find objects of type,
health handler, boss, health handler.
And we are going to get the current.
So I'm going to duplicate this one.
Get boss, current health,
current health, save that.
So this is just a return method of integer.
Nothing too complicated.
So get boss current health all the time.
And now let's go ahead and assign the slider.
So open this up.
The slider and work is the slider.
This one is the sliders save all of that.
Let's make this a bit bigger, run the game.
So now we should see
the health slider move
the enemies both so you shoot him. There we go.
So as you can see,
his health gets smaller and he gets
angry right about the halfway point of our game.
Finally, when we shoot them for the last time, he dies.
But we still have this health bark.
And not only that, we have
this small error appearing in here,
well actually not a small error, a constant error.
So I'm going to collapse it.
Double-click in here and see what the problem is.
Find objects of type.
So this is a null reference.
Null reference means that we are
trying to get a reference to
something that does not exist or the return is not.
So in here we have the boss health handler.
And obviously when we die,
we destroy the boss.
And when we destroy the boss,
the boss health handler goals William.
So we need to find a solution to that,
and that is going to be your challenge.
Your challenge is to remove
the Health Bar and make the boss invincible.
Maybe your challenge isn't to fix the error.
Anyways, let's see what we have in here.
First of all, when the boss dies,
make sure that the health bar is
removed and stop the error.
You'll need to obviously remove
the Health Bar and remove the image and the picture.
So we don't no longer have to
call that every single time.
Then you'll need to make sure that when
the bus is going into the angry state,
we want to make him invincible.
So when he is getting angry,
we don't want to be able to shoot him.
This is first of all, not
fair to the boss because he cannot
attack us or move when he is getting angry.
Second of all, because in every single game
when a boss transitions into the second phase,
you cannot hit him.
This is something standard and all games.
So I'm going to give you a hint
of how to do the last part.
You'll need to add behavior to the get anger state.
And as I told you,
we need to fix the problem of the error.
While obviously when we actually disable the half bark
at no longer calls for
the players held the bosses health handler,
so we no longer have the arrow.
So with that information,
pause the video right now and go do the challenge.
So, okay, welcome back.
So the first thing that we're going to do
is we're going to go into the update and here.
And we're going to check if
the boss health slider dot value
is less than or equal to 0,
that means that we are going to
destroy the entire game object.
Now we, we don't have to destroy the game object.
We can maybe set the game object to active,
false, or set it to inactive.
But I'm just going to destroy it just
so we make sure we don't have anything anymore.
So save that.
And then we are going to go into the boss health handler.
And in here we are going to create a variable.
And that variable is going to be
a public bool and is in invincible.
And it's going to be set
to false at the beginning or you know what?
Let's not make it public.
Let's make it a private.
And we'll create a method in
here that is going to be public,
int or no, Actually, sorry, void.
Set.
The boss.
Even subtle.
And it's going to take in a parameter which is a Boolean.
And it's going to be is
Skelly or normal not
that is boss in a given symbol.
And then in here we are going to say that is invincible
is equal to, is boss invincible.
Save that.
And in here, before we take damage, as you can see,
we have the comment if getting angry,
this should not work.
So we're going to say, if is invincible,
then we are going to help,
then we are going to just return.
So return means.
When we do return,
just like we have the return values
and here once we get to the return,
this entire method stops.
So anything under this line of code.
So in here, anything that we write will
not be registered after the return.
And this is exactly what we do in here.
So when we take damage in here,
we check if he is invincible.
We open this one up.
Sorry.
We enter into the condition,
we execute the return and none
of these lines get executed.
So we basically return a value,
and because this is a void,
we can return anything.
If it was an integer,
not a void, we could just return 0.
So I'm going to remove this.
I'm going to save all of this.
And now how are we actually going to
be setting the is invincible?
I'm going to go back in here.
I had this one running.
And let's this out.
First of all, the Health Bar.
So Shruti, should the Shruti.
Surely, there we go.
And when he finishes this animation, he will die.
And you can see that we no longer have
a health bar and we no longer have any errors.
Excellent.
Now the next thing to do is to go into
the animator and to the getting angry state.
And why is this not becoming smaller?
Okay, so in the end,
get angry, we're going to add a behavior.
We're going to call it the boss, underscore, get angry.
New script, create an ad.
And obviously it will be created in the assets in here,
the boss get angry.
I'm going to move it into
the scripts Boss folder
for file or whatever you wanna call it.
So was, there we go.
So both get angry.
Open this one up.
As we can see, the last two we will not need.
And these ones will be control KU.
Control key, you can control KU.
So in here, what should we be doing?
Where should we be making sure that
the boss is invincible or setting it up?
Well, I believe we should first of all,
set it to true when we enter into the state.
So I'm going to access the animator component.
So now we have access to the boss health handler.
And in here we are going to set
the boss invincibility to true.
And then when we exit,
I'm going to duplicate this line and move it down.
And when we exit the state,
then we again can get hit.
So as you can see,
right here, we've created the set boss invincible.
We have a parameter that we need to send it.
We access it using
the component of the boss health handler,
which is also present with the animator.
So we have both components on the same game object.
That's why we can access the animator,
get a component which is
the half Handler said the boss invincibility to true.
And in here, when we said is
invincible to whatever the boss,
invincible whatever the parameter.
If it is true, then it returns.
If it's false, then we do not return.
The boss takes damage.
We save that.
We go back into our game.
Who were.
So up here, we run the game.
We should the bus once, twice.
And you can see right here that while he is angry,
he does not get damaged.
So I've shot him three to four times.
He does not get damaged.
Finally, I shoot him, he dies.
And there we go.
We'd have no errors except for this one which is I
believe something that isn't any of our concern,
something about the panel.
We have this OK time.
So we're going to go out,
we're going to make sure to stage all of our files and
now created a health bar.
So I hope you enjoyed,
excuse me for the long video,
but this is what happens when we are creating UI.
This is all based on your preference,
how you want your game to look.
And I'll see you in the next video.
And I believe the final video where we will make
the boss actually shoot after a certain amount of time.
So see you then.