Let's fix the box.
Basically what we have to do.
We need to open up our player script.
So let's go to player script.
And we're just checking if the script is uh, not equal.
Equal equals to null.
Then we typing return basically means this enemy to game object is totally that.
We do know that enemy two script just gonna destroy with that enemy two game object as well.
And we're checking over here.
So I'm going to remove this.
Instead of doing that we're going to check it over here as you can see.
So we're just damaging our enemy two as well as enemy one.
So before we damage we need to check if the script is attached to enemy game object or not.
So we just, uh, damaging our enemy to game object, as you can see over here.
So what, we basically want to check if we want to damage this enemy two game object.
Uh, we do know we're just shooting out line renderer uh, line renderer line renderer.
And once we delete this enemy two game object enemy two game object, we also destroying this anime
two strip as well.
We do know that if we destroy this anime two game object, it will destroy this anime two scrape as
well.
So what we basically need to do before we damage our enemy two game object or this anime one.
We need to check if the enemy to skip is attached to this anime two game object or not before we just
damage it to this anime game object.
So what we will do, we will go to Skip and over here.
As you can see, we just damaging right away if the ray just collided with this enemy to game object
or not, we just damaging right away.
So before we damage we need to check if the enemy two script is attached to this enemy two game object
or not.
And we can see in Inspector Anime two script is attached to this anime two game object.
So before we damage we gonna check so we will check.
If so we're going to use this hit info parameter, then transform.
We're going to move over to that.
And then we're going to use this get component in order to get the component.
And the component we're looking for is our enemy two script.
So we're going to pass enemy two and make first bracket.
And we will check if it's not equal to null.
If that is the case then we're going to make some curly brackets.
So in that situation what we need to do we need to damage our enemy two game object.
So what we basically have done over here hit info transform basically means the game object that collided
with.
So the rage definitely collide with this enemy.
Enemy two game object.
So basically we're just going over to this enemy two game object transform component.
And by this transform we're just moving over to this enemy two script, as you can see in the Inspector.
And we're checking if that enemy script, enemy two script is not equal to null basically means the
enemy script is attached to this player game object.
Sorry, sorry.
I'm really apologize for it.
So enemy two script is attached to this enemy two game object.
As you can see, the script scrip is not equal to null means the scrip is really attached to this anime.
Two.
Game object.
And we can see definitely.
Indeed the anime two scrip is attached to this anime.
Two.
Game object.
So we are now ready to damage this anime two game object.
So that's why we're going to put this line of code by control X, and we're going to put it inside this
curly brackets by Ctrl V.
Then what we're doing we're just going over to hit info dot transform.
So the array is just going to collide with this anime two game object.
So hit info dot transform means this anime game object transform.
And by this transform we're just going over to this anime two script.
And we do know inside this anime two script, we just created a function called Take Damage.
And we do know what that function really doing.
It's just a it's just making our enemy two game object taking damage.
So that is the thing we have.
We just doing it.
And also we're going to check for first enemy.
So we're going to do the same thing.
So we're going to use this hit info dot transform.
And in order to extract information we're going to use this else if condition.
Now we're going to check.
So we're going to use the same uh, same line of code by Ctrl C.
And we're going to paste it inside this bracket by Ctrl V.
And now we're going to check if the enemy escape.
So it's going to reference the first enemy.
Or you can simply say the first enemy or the enemy one.
And we're going to make some curly brackets.
So we're just doing the same thing.
Basically we're just looking for enemy script.
And if it's not equal to null means this enemy script attached to our enemy game object.
So in this moment we are ready to damage our enemy game object.
So that's why we're going to put this line of code.
Basically we damaging over here as you can see.
So we're going to press down Ctrl X in order to cut.
And we're going to paste it over here by Ctrl V.
Then we're just going over to that game.
Object means enemy.
Then we're just moving over to enemy script.
And from there we're just calling the Takedamage function.
and this function just doing the right thing.
And now what we're going to do inside the putting the or setting the second position where the ray hit
width.
We're going to put this line of code inside this curly brackets.
So it's gonna collide with enemy two.
Game object means our ray should be set over here because it's gonna collide with this enemy two game
object and should it should not be passed through that this enemy two game object until and unless this
enemy two game object dies.
So that's why we're going to set the position as well.
Means our second position, Ray.
So we're gonna put it inside this curly brackets.
So let's press down control X for cut.
And we're going to paste it inside with first enemy as well by control V as well as we're going to put
it over here control V.
So basically we're just setting the second position of the line renderer component and hit info dot
point basically means where the ray collided with.
And we're doing inside this enemy anime one or this anime script means the first anime, then we're
setting the position.
Second position it info dot point over here.
It's just going to reference the first anime the Ray hit with.
So we're just taking that position and we're storing into the first one index.
And we're just doing the same thing in anime two.
So hit info dot point basically means over here the ray hit with that anime to game object.
So if the ray hit with this anime two game object.
So we're just taking that position and we're storing into this one index.
If the ray just collided with the second anime, and if the ray collides with our first anime, then
we're just setting that position.
And over here just going to be hit info dot point right now just going to be the first anime.
So basically it's going to collide with the first enemy.
So that's why it's going to set the position of that line renderer.
Second position uh, to that point where the ray collided with Lightweight.
The first enemy.
And basically we're just doing the same thing.
And if you are still a little bit confused, then don't worry, I'm gonna have a video in the resources.
If you just want to grab it more deeply, then you can check that video as well.
I'm gonna have it in my resources so you can check that out if you just want to learn more deeply.
So you can simply check that out.
And now I'm gonna press down Ctrl X in order to save my script.
And let's move over to unity by now.
So by now the error should be gone.
But let's have a look on that.
So I'm going to press down Ctrl X sorry Ctrl S in order to save.
And let's move to unity.
So make sure you just save your script or else you're gonna get some weird errors in your console tab.
Uh, so make sure you just press down Ctrl s, or you can just go over to top left file and then click
on that save button.
And now I'm going to click on this play button in the top to play our game and the error should be gone
by now.
So just wait for it to compile and then we can have a look on this.
So let's attack on this, uh, enemy two game object.
And uh, now we can see it just setting the position as well as the enemy two game object gets, uh,
get destroyed.
And also the messages get pop up in the console.
Says enemy two died because once our enemy two game object or the enemy loses all of his health, then
we're calling the die function.
And inside that die function, we're just printing out a message in the console.
Says the enemy died, uh, with corresponding name.
So I'm going to get out of play mode.
And that is the cool thing.
I hope you get the idea.
And I'm going to press down Ctrl s to set my project.
And also let's select the enemy two game object overrides and we're going to click on this Apply all.
So if you change anything in the inspector it's going to be saved into this enemy GameObject prefab
as well.
So basically that is the thing.