Let's give some health amount to this, uh, anime two game object in order to take the damage.
So we're going to approach the same way we have done.
So let's do that.
So let's open up the anime two script quickly, and let's go to the top of our class and let's declare
a variable, or let's give it some help to our enemy game object.
So let's make a public that will be int, and we can simply call this one Max.
Uh max health and max health.
And by default I'm going to set uh, something like two unit of health.
And let's close that up with semicolon.
And let's make a function take damage somewhere over here.
And we're going to make that function public because we're going to call this function through another
C script or through another C class, uh, from where our player game object shooting onto that enemy
game object, we're going to call the function there.
So let's make this function public.
And for function we're going to type void.
And we're going to call this function to something like take damage and let's make first bracket or
some curly brackets.
So you can give an parameter or argument over here.
I'm not going to do that.
I'm going to do in a different way, uh over here.
So what I will do, I will subtract from this max health.
So we will go to max health minus equal one.
And then we can close that up with semicolon or simply what you can do.
You can just pass in damage and you can just pass the damage over here parameter.
And you can simply later on replace this with one.
But I'm not going to do that for now.
And uh, so if we call this Takedamage function for the first time.
So the max health by default we have given to, as you can see.
So this one is two.
So two minus one is just going to be one.
And if we call this takedamage function for the second time.
So the max health is now one.
So one minus one is just going to be zero as you can see.
So the max health of our enemy two game object just gonna shrink down to zero.
So once our maxhealth is totally zero zero of this enemy two game object, then we need to stop calling
this function.
Or we need to stop subtracting the max because the max health already gonna be zero.
So that's why.
So before we subtract, we're going to check if max health is less than or is equal to zero means it's
already zero, then we're going to make some curly brackets.
So in this moment we need to stop doing this thing.
Basically we need to stop subtracting our max health.
So we're going to type this return.
And let's close that up.
Semicolon.
And let's make a also a die function in order to destroy our enemy game object.
So we're going to do it something over here.
So let's make a void for function.
And we're going to call this die and make first bracket and some curly brackets.
And what we want to do inside this function we're going to destroy this enemy two game object right
away.
So let's do that.
Firstly I'm going to print out a message.
So I'm going to type this debug dot log and log.
And I'm going to say this dot transform dot name.
And top of that I'm going to add a custom message something like says diet.
And let's close that up with semicolon.
So this dot transform basically means it just referencing itself.
So we're just going over to this meta game object transform.
And by this transform we just accessing the name.
So the name we can see is anime two.
So this is just going to be anime to the name.
And top of that we added a message says diet means anime to anime to diet.
Just gonna uh, just gonna pop up underneath our console tab.
And after that, we're gonna destroy this Army two game object right away.
So for that, we're gonna use the destroy function.
So let's go to script.
After printing out message, we're going to use this destroy.
And it's going to take the game object you want to destroy.
So we're going to destroy itself.
So that's why we're going to pass this dot game object means it's up.
And let's close that up with semicolon.
So we also need to call this this die function and die function.
Firstly it's going to print up the message in the console says I'm too tired.
And after that we just destroying right away as you can see.
So we need to call the die function.
But when we shoot once, our max cell of anime tube game object loses all of his health, or the Maxwell
just became zero.
So then we're going to do that thing.
So let's go to update function.
And update function runs every single frame.
So that's why we're going to do right there every single frame we're going to check the max cell.
We're going to type this if if max health is less than or equal to zero.
And let's make some curly brackets mean.
Now we need to call the die function and die function to gonna do the rest thing.
So let's call the die function here and make and close that up.
Semicolon.
So we're checking the max health of our enemy two game object.
So the max health is already is if the max cell is less than or equal to zero, then we're calling the
die function.
And what die function is doing is firstly printing out the message in the console says enemy two died.
As you can see.
And after that we're just destroying our enemy to game object right away.
And we're going to press down Ctrl S in order to save our script.
And let's move to unity.
So we also need to call the Takedamage function in order to take damage on this enemy two game object.
So we also need to call that Takedamage function.
We just made it, uh, we never calling it so our Maxhealth will not move over to zero.
So that's why we need to call the Takedamage function.
But when we're going to call it once our player GameObject shoot it, shoot on this enemy two game object.
So we're going to do call the function there.
So let's do that.
So going to select our player GameObject in the hierarchy.
And let's open up the player script quickly.
And let's call the function where we're shooting.
So as you can see we're shooting it over here.
If hit info is true row means the ray just really colliding with this anime game object.
Means this anime game object need to take the damage.
So let's call the function here.
Here where we create.
So we created the damage function in this anime two script.
So we're going to move over to this anime two script.
And then we're going to call this Takedamage function when we're shooting on that anime game object.
So let's move over to our player script and let's do it over here.
Because over here the the rage is colliding with our enemy game object.
So when I use this hit info dot game, hit info dot transform, we need to use then get component.
And the component we're looking for is a, uh, is a uh, you can simply say our enemy two script.
So let's pass here.
Enemy two sorry, anime two.
Enemy two.
And let's make first bracket.
And then we're going to call the function here.
So take damage and make and let's close it up with semicolon.
So we do not need to pass any argument over here because there we haven't given any argument.
So that's why.
So what we basically doing we just going over to hit info draw transform and hit info dot transform
basically means the game object that we collided with.
So if we shoot out the ray from this player game object and the ray just hit this enemy game object,
then we just moving over to this enemy game object transform component.
And by this transform we just moving over to this enemy two script, as you can see over here.
And then basically we're just getting the enemy two script or the enemy to C-sharp class, as you can
see.
And from there we're just calling the Takedamage function.
So we're simply going over to this enemy two script and then calling the function this.
We're calling this Takedamage function.
And we do know what we're doing inside this Takedamage function.
We just subtracting from our max health by this amount of unit, as you can see.
So I hope you get the idea.
So now we need to save our script.
So we're gonna move over to player script and let's press down Ctrl s in order to save.
And let's move to unity.
So whenever this, uh, this player game object just gonna shoot on this, uh, anime two game object,
you will see this anime two game object.
Just gonna take the damage right away.
So let's have a look on this.
So I'm going to select my anime two game object.
And let's click on this play button in the top.
So the max file by default we have given two.
As you can see underneath our anime two script in the Inspector.
So once we, uh, shoot on this anime two game object for the first time.
So the max is just going to be one.
So, uh, so let's have a look.
Okay, so we get an error.
So we need to get out of play mode.
Basically we need to assign this enemy to as a enemy layer because we only checking for that layer.
So if we move to player players escape and we can see we have passed.
What is enemy?
Basically we only checking the enemy layer and we can see if we select enemy two GameObject in the hierarchy
and move over to Inspector.
We can see we have an assignment this enemy to GameObject as a enemy layer.
So and if we select our player GameObject in the hierarchy, then move to player Skip.
We can see what is enemy is chosen.
Enemy means the ray.
Just gonna check only for this enemy GameObject.
So we need to assign this enemy to as well as enemy layer.
So let's select the enemy to GameObject in the hierarchy and the top right we can see layer and it says
default.
So let's assign it with this enemy.
And I'm going to click on this note.
This object only means the parent I only want to change.
And we can see by now we assigned this enemy as enemy layer.
So let's go to Over edge and then click on Apply All.
And now we're going to select our player.
And we can see enemy.
So it should be fine by now.
So let's have a look on this.
So let's click on this play button in the top two able to see.
And we're gonna able to see that this enemy just gonna take the damage right away once we shoot on this
enemy two game object.
So if I select and then shoot and we can see now the enemy two just get destroyed right away.
Once we just, uh, once that enemy game object just, uh, loses all of his health.
As you can see now, it's fine.
I hope you get the idea.
So we're gonna get out of play mode and what we want to do.
So once we shoot on this enemy game object, we're gonna spawn the floating tags, as we have done with
the first enemy.
So we're gonna do the same thing in this enemy two game object as well.
So let's do that.
And also once our enemy two game object loses all of his health.
So before it get destroyed, we're gonna show up the explosion effect as well.
So let's do that.
So we're going to do the same thing as we have done with the first anime or anime one.
So let's do that.
So let's open up our anime script.
So when I spawn the floating text as well as the explosion effect.
So let's go to top of our class and we're going to make it over here.
So let's make it public.
And we're going to create a game object container.
And we need a reference to that floating text prefab.
So we're going to type floating text.
Basically we have to name it.
So I'm going to call it something like floating text prefab.
And also we need the explosion effect reference.
So we're going to create a another public game object.
And this one is just going to be explosion explosion effect effect.
And we also need to create the point basically where I want to show the explosion effect.
So I'm going to show the explosion effect from the bottom.
So I'm going to create or we need a reference of a bottom position.
So we're going to create a point a position from in this anime anime two game object, and from that
we're going to show up the explosion effect.
So that's why we also need a reference of a position where we want to show the show up, the explosion
effect.
Or you can simply pass transform dot position.
So you don't need to have a reference of any position.
Transform dot position basically means centered position of our anime game object or the current position.
But I'm going to create a a point from where I want to spawn my explosion effect.
So that's why I'm going to create a public transform which is responsible for position.
And we can simply call it something like spawn effect point or position.
So I'm going to call it something like point.
And let's close that up.
Semicolon.
Let's press down Ctrl S in order to save our script.
And I'm going to remove this start function from here.
And also this comment I don't need this for now.
And let's press down Ctrl s to save scrape.
And let's move to unity by now.
So we need to assign those variables one by one.
So the first thing just gonna appear our floating text.
So we can see underneath our enemy to scrape a floating text prefab just appears slot appear and it
says none.
Game object means empty.
So we need to drag the floating text prefab game object over to this slot.
And then also we need to drag the explosion effect.
So let's go to project tab, then assets and then prefabs folder.
I have the explosion over here as you can see.
So I'm going to select and I'm gonna drag it over to this explosion effect slot.
And I'm going to select my floating text game object.
And I'm going to drag it over to this floating text prefab game object.
And also we need to need a point from where I want to show up the explosion effect.
So I'm going to create an empty game object in this anime to game object.
So let's right click on this anime two game object.
And let's create an empty game object.
And I'm going to name this claim object to something like spawn effect point or spawn effect position.
So I'm going to call it spawn effect effect point.
And I'm going to move this one.
Sorry, I'm going to move this one in the bottom or fit of my this anime game object somewhere over
here not in bottom because the center position of the explosion just going to be over here.
So the bottom just gonna cover up and I'm going to choose energy gizmos for that as well.
And now let's select our anime script and let's drag the spawn effect point right there.
Now we can see we have the reference.
So I'm going to move over to overrides and then apply all.
So we have all of those things.
So let's open up our anime two script by now.
And we're taking the damage over here as you can see.
So what we're going to do we also gonna spawn the basically we also want to spawn that floating text
prefab once we take damage.
So I'm going to use this instantiate function.
And this function over here.
It's going to take as a first argument the game object you want to spawn.
So I'm going to pass my floating text prefab game object.
And the second thing it's going to take the position.
So I'm going to pass my transform dot position means the current or center position of our enemy to
game object.
And the third thing it's going to take the rotation.
So we're going to pass quaternion.
Dot identity basically means no rotation.
And let's close that up with semicolon.
And we also need to show up the explosion effect.
So let's move over to die function.
So before we dive we're going to spawn the explosion effect.
So before we dive we're going to use this instantiate function as a first argument.
It's going to take the explosion effect or the game object you want to spawn.
So in our case explosion effect.
And the second thing it's going to take the position.
So we have the position which is our spawn effect position.
So we need as a second argument we're going to pass that which is spawn effect is spawn effect point.
And then we're going to access the position basically where from where we want to spawn.
So I just move it over to spawn effect position basically this one and then access this position.
And now the second uh third thing, it's going to take the rotation.
So I'm going to pass quaternion dot identity basically means no rotation.
And let's close that up with semicolon.
And I'm going to press down Ctrl s to save my script.
And let's move to unity by now.
And let's have a look on that.
So just wait for to compile.
And once it's done we are ready to do that.
So now let's have a look on this and make sure you just drag all of the reference one by one into that,
into those corresponding slot.
And let's click on this play button in the top to play our game.
And we're going to take a look on that.
So just wait for it to compile and have a look on this.
So now if I just, uh, just, uh, basically shoot on this anime game object, we can see it's just
getting spawning and, uh, explosion effect as well.
But the problem is that if I pause my game and then move over to hierarchy, we can see the explosion
effect is still there as well as, uh, we don't have the floating text, so we can just ignore that
so we can still able to see our explosion effect, as you can see.
So we need to destroy this explosion effect after some period of time, basically, after completing
the explosion effect animation or after that amount of time, we're gonna destroy that.
So we're gonna get out of play mode and let's move over to Inspector.
We get an error.
So if I just double click there so we can simply ignore this.
So now what are we going to do?
We're going to destroy that.
So let's open up our animated script quickly.
And over here, as you can see, we spawning.
So after spawning that explosion effect prefab we're going to store that into another GameObject or
another container.
So we're going to store that.
So let's make a game object because this is explosion effect itself a whole game object.
So that's why we need to put it in a container called a game object.
And we have to name the container or the variable where we want to store it or where we want to store.
So I'm going to call it something like name explosion game explosion a effect.
And let's set equal to this name basically means temporary name explosion effect.
So basically we spawn it this explosion effect at this point with no rotation.
And after that we just taking this explosion effect what we spawn it we storing that into this explosion
effect as you can see.
So we directly setting it basically means we just storing that.
So we also need to delete the container or where we store spawn where we stored that explosion effect.
So we need to destroy as well that whole game object.
So let's do that.
So after storing that we're going to use this destroy function.
And this destroy function is the first argument.
It's going to take the game object we want to destroy.
So in our case we're going to destroy.
This explosion effect basically means where we store the explosion effect prefab after spawning that
and we're going to destroy basically we just destroying the whole container where we store it.
And as a second argument, we need to specify the time after which amount of time.
You just want to destroy that.
And if you just don't assign it with anything and then close that up with semicolon, it's gonna destroy
right away.
But we do know we need to play the 100% animation clip of the explosion effect.
And after that amount of time, we're gonna destroy.
So that's why, as a comma.
We're going to specify this at the time as a second argument.
So before we do make sure you just go to unity and then project tab prefabs folder.
Basically open up that explosion effect and move over to this animation and see after which amount of
time, after how amount or how much amount of time you just completing the animation clip.
And you can see 0.9 just a lesser than little bit one second.
So we're going to put 0.9, which is going to be perfect time, because after this amount of time,
we can see the animation is just completing whole basically one over here just referencing one second,
you can simply say, so this is going to be over here 0.9 second.
So as a second argument we're going to specify the time.
So let's go back.
Let's go to script.
And as a second argument I'm going to pass 0.9 F.
And let's Ctrl s to save our script.
And let's move to unity.
Basically press down Ctrl S in order to save your script and then move to unity.
So after 0.98 second, you will see that will be also destroy the container where we store it.
So let's see let's see that.
So I'm going to click on this play button in the top and have a look on this.
So just wait for to compile.
And once it's done we are ready to do that.
So if I just attack on this uh, anime two game object and we can see it's getting destroyed and we
still able to see this line renderer.
So we also need to, uh, destroy that.
So if I move over to console, then open up the anime script.
Uh, so we're doing it over here.
So we just, uh, basically what we're doing, we're just checking if, uh, startcoroutine over here,
as you can see.
So what we will do for.
So we're gonna remove this messages, uh, messages.
So basically what we are doing over here, uh, we basically destroying this enemy game object, but
we still able to damage it.
Or just shooting that line runner.
As you can see.
So before we shoot or do all of these things or damage this enemy to game object, we need to check
if this enemy to game object is still in the scene view means in the game or not.
If it's totally destroyed, means we need to stop doing what we're doing, like taking damage.
So we need to do that.
So let's go to step.
And before we do all of these things, or we can simply go over to this where we just clicking the left
mouse button and we just simply doing these things.
So or we can simply move over to this shoot function in enumerator.
And we can check over here what we will check we will check over here.
We're going to check if uh if we're going to use this find any object uh object by type.
So make sure you use this and into arrows.
You need to pass the script name which is script you want to check for.
So let's suppose this anime two game object just died.
So with this, this anime two script is also gonna be destroyed.
As you can see, the anime two script is attached to this anime two game object.
Which means if we destroy this anime two game object, the script will be also be destroyed.
So we're going to check right there.
So we will pass the anime two script and we will check if this anime two script.
So make first bracket and some the basically make sure you just doing as I did over here.
So we simply going over to this anime two script and we're going to check if this anime two script is
equals equals to null equals equals to null basically means empty means we don't have the enemy to script
in this in view or in the game means the anime two game object gets destroyed.
So in that situation, we need to stop doing all of these things like setting up the line renderer,
shooting out on enemy game object.
So that's why.
So we're going to make some curly brackets.
So we're checking over here.
If the enemy to skip is equals equals to null basically means enemy to skip.
Just get destroyed.
And we don't have enemy to skip in this in view or in the game.
So we need to stop shooting on our enemy to game object.
So that's why we're going to type this return.
And we do know after return whatever we're gonna do it's not gonna work.
Uh, not work, it's not gonna work.
And we get some error, as you can see.
So what we're going to do, we're going to put this line of code, uh, over here where we're just clicking
the left mouse button and then shooting on this enemy two game object.
So we're going to put this line of code.
So I'm going to press down Ctrl X in order to cut.
And I'm going to paste it over here where we just clicking by Ctrl V.
As you can see by now it should be fine.
So let's press down Ctrl S to save our skip.
And now let's move over to unity.
So we will see that error just be gone by now.
But let's have a look on that before we just, uh, do those things.
So we need to check if it's perfectly working or not.
So we should not see any messages.
So let's click on this play button in the top.
And let's take a look on this.
So if I just, uh, shoot on this anime two game object, you will see that.
Still we able to see and we can see object reference is not set.
So we need to fix that.
We need to, uh, do something that we really want to do.
So over here we're going to do that, but we're going to take a look or we're going to fix this bug
into next lecture.
And you can just leave it, uh, this one, it's totally fine.
You just have to check.
So make sure it's basically totally fine.
So I'm going to press down Ctrl S in order to save my script.
And let's move to unity.