Now what we will do.
We are just gonna damage our player game object.
Basically what we want to do if we select our enemy to GameObject in the hierarchy, then move over
to the animation tab and select the Attack Animation clip.
As you can see right over here.
So we will create a attack point somewhere around here.
And from that point we are just going to create a circle.
And if that circle collide with this player game object, then this player game object just gonna take
damage.
So we will do the same thing as we have done with player attack.
So we are gonna do the same thing or we're gonna approach the same way.
So we're gonna create a attack point somewhere around here.
And from that point we just want to create the circle.
So let's open up our enemy two script by double clicking on it.
And let's let's make it over here.
Uh, we're going to make it somewhere around here.
It does.
It doesn't need to uh, doesn't need to be in order.
You can make it anywhere you like.
It's basically up to you and we will make that function.
We will make this function public.
Why?
Because we're going to call this function through animation event basically right over here.
It's going to be perfect time.
So we will call the function here.
So that's why.
So we're going to mark this function as public.
For function we're going to type void.
And we have to name the function.
So we're going to call it something like attack.
Let's make first bracket and some curly brackets.
So inside this function what we want to do we want to create a circle from that point.
And we do know that to create a circle we need to use this physics 2D physics 2D dot overlap.
Sorry uh sorry overlap circle function.
And we do know that this function as a first argument, it's going to take the point from where we want
to create the circle.
So we need to create an empty game object.
And we can just name that to something like point attack point.
And the second thing it's going to take the radius.
And the third argument it's going to take the layer mask basically which game object we want to damage.
So let's make this one a comment by double forward slash.
And let's go to the top of our class.
And let's assign those variable.
So we're going to make it somewhere over here uh somewhere over here.
So let's give it a header or title.
Let's give it a title.
And we're going to say something like attack.
Uh, let's say attack.
So what we need.
Uh, so let's make a serialized file.
So we need position basically means transform.
So when I create a private transform and make sure you just mark as serialized, you can, uh, so you
can notice underneath your inspector tab, underneath your enemy to script.
And we're going to call this one something like attack point.
And the second thing we need the radius.
So let's make a another serialized field private.
And we're going to call this one attack radius.
Sorry.
Let's call it attack Radius.
And by default I'm going to set something around one unit one if something like that.
Sorry we need to type this float.
So let's type this float equal to then attack radius.
And by default I have given one f.
As you can notice.
And we also need to assign the layer masks.
But we already already created right over here as you can see.
And we just we just created a field called What is player.
So we can make it one more time layer mask.
But I'm going to use the old one since we just going to damage our player.
So this what is player layer masks.
We assign it that player.
So that's why I'm not going to create it one more time since this since we already have it.
Basically we want to damage our player.
And over here layer Mask we just assign it player.
And what we're going to do now we're going to press down Ctrl S to save our script.
scrape.
And now let's head over to unity.
So as soon as our enemy two script just gonna compile those, we're just gonna pop up.
So first thing, we'll pop up a attack point and by default, and it's gonna be empty.
So now.
So if I select my enemy two GameObject in the hierarchy, then go over to Inspector Enemy two script.
As you can see, it will be none.
Sorry, sorry.
We didn't, uh, basically saved our code.
We need to move over to script one more time, and let's press down control s one more time in order
to save our script.
And now let's move over to unity.
So now it's gonna be fine.
So we will see a attack title underneath our enemy two script in Inspector.
And we need to assign those variables one by one.
So the first thing we need a attack point.
So we will create an empty game object inside this enemy game object in the hierarchy.
And we're going to call that GameObject to something like attack point.
And from that point we just want to create the circle.
So that's why.
So just wait a moment and once the compilation is done, we can just go ahead and we can just assign
those variables one by one.
So if we move over to Inspector Animator script, we can see in the bottom a tag title pop pop up and
attack point.
As you can see it says none transform basically empty.
So let's create a attack point.
So let's select the enemy to GameObject in the hierarchy.
Let's right click on it and create an empty game object.
And you can name that game object to something like Attack Point.
So I'm going to call it Attack point.
So let's call it Attack point.
And I'm going to choose an gizmos for it to do to to choose that we will go over to Inspector.
Let's click here in this box.
And we're going to choose an gizmos for it.
So I'm going to choose yellow.
And we're going to select our move tool from the scene view.
And let's move it somewhere around here.
But before you move make sure I'm going to select my enemy to GameObject first.
And then let's move over to this animate uh animation tab.
And we're going to choose the attack animation.
And let's say so we need to move this attack point somewhere around here.
So it's just going to be middle center.
So that's why from that position we just want to create the circle.
So before you just uh before you change your attack point position, make sure you select the animation
tab and then check with attack animation and perfectly place that, uh, that attack point.
So we need to move this attack point over here.
So it's gonna be center position.
So I will select my attack point and let's move it somewhere around here.
And this seems pretty much fine.
So from this point we just want to create the circle.
Now we assign it.
So sorry we just created.
Now we will choose our attack point underneath our animator GameObject in the hierarchy.
Then sorry drag it over to this attack slot.
In the bottom you can see attack Point.
So let's drag it there and attack radius.
By default we have chosen one, as you can notice.
And what is player?
We already assign it with player, so we don't have the third argument since we already have it.
What is player?
I have chosen player since I want to damage my player game object.
So that's that's why.
And let's select the parent game object basically enemy two.
Let's go over to Inspector Overrides and then apply it all.
So the changes you made, it's going to be saved into your enemy two game object prefab as well.
And now we're going to open up our enemy two script by double clicking on it.
And let's move over to Attack function.
And let's remove this two forward slashes.
So what we so as this function as a first argument, it's going to take the point from where we want
to create the circle.
So we're going to pass our attack point dot position.
And the second thing it's going to take the radius.
So we will pass our attack radius.
And the third argument it's going to take the layer mask basically which game object we want to damage.
So in my case it will be player.
So layer mask I'm going to pass this word is player.
And we do know that we have seen already what is player.
We assign it player.
And now we're going to close that up with semicolon.
So this physics 2D function it's gonna create the circle from this attack point position with this radius.
And it's gonna target or it's gonna damage our player game object, as you can see.
So it's gonna create the circle from this attack point with this at that matchup attack radius.
And if that circle really collide with this player game object, then this function right over here,
this whole function, it's gonna give us a true value if the circle is really colliding with this player
game object, and if it's not, then it's gonna give us a false value.
So what we will do, we're gonna store it into a container.
The result, and we will store it into a collider 2D.
Why?
Because this physics 2D overlap circle just gonna work as collision.
So that's why we need to put it in a container or a variable.
Or you can simply say in a parameter which will be collider 2D.
So the type of the variable will be collider 2D or the parameter.
And we can call this one to something like call info or collision information short for.
And let's set equal to this.
So this call info right over here it can be true or false depending upon if the circle is really colliding
with this with this player game object or not.
Let's suppose the circle we created is collide with this player game object.
So this function is just gonna be true.
So that's why this call info right over here.
It's gonna be true.
Why?
Because we directly setting it.
As you can see, Collider 2D call info equal to physics 2D dot overlap circle.
So in the next time.
So in the next what we will do we will check.
So let's make this if condition and first packet and some curly brackets.
And what we want to check over here.
We basically want to check if call info is equals equals to true.
Or we can just leave it like this.
It's also basically means true means uh, our uh, circle is really colliding with this player game
object.
And we do know that we're checking if call info is true.
Basically means that circle just colliding with that player game object.
So right now what we need to do, we need to damage our player.
So for now we're going to print out a message.
But before we print out a message we just want to check uh, check if the circle is really collided
with this player game object or something else or not.
So we're going to check that.
So that's why if call info is true basically means the circle is colliding with that player game object.
So we also want to check if the game object the circle collider is the circle collided with.
If that game object has a script called player script or not.
And if we select our player game object in the hierarchy, then go over to Inspector.
We can see a player script is attached to this player game object.
So we just want to check if the circle collided with this player game object and the player script is
attached to this player game object, then what we want to do, we want to damage.
But before we before we damage, we're going to print out a message.
And before we print out message, we also want to check if that game object has a script called player
or component called player a is player script is attached or not.
So that's why before we print out message, we just want to check if let's make first bracket, add
some curly brackets and what we want to check over here.
We basically want to check if the circle collided with the game object.
So the circle definitely collided.
Just going to collide with the player game object.
So we just want to check if that player game object has a script called a, has a script called player
or not.
So what we will do, we basically do this thing we call info dot game object and call info dot game
object basically means the game object the circle collided with.
And now what we're going to do, we're going to use this dot get component.
And the component we're looking for is player.
So we will pass player uh player.
Or you can simply say player skip and then make this first bracket.
Uh, so we just take getting the player skip and we will check if it's not equal to null basically means
that our player script sorry and not equal to null if it's the case uh, means we are ready to damage.
So firstly what we're doing, we're checking if the call info is true.
Basically means that we created the circle is really colliding with this player game object.
And once it's collide what we doing.
We firstly going over to that game object so called info dot game object basically means the game object
the circle collided with.
So in our case it's going to be player and we're just trying to get the player skip, as you can see.
So we just are going over to this player script and we're checking if the player is script is not equal
to null.
Basically means this player is script attached to that player game object.
And if we move over to unity, we can see indeed the player script attached to this player game object.
So basically means it's true.
Now what we can do, we can simply damage our player.
But before we damage it, let's print out a message.
Since we didn't, uh, given uh, given any uh, health amount to our player game object.
So that's why for now, at this moment, we just only want to print out the message.
So we're going to type this debug.log for printing out message.
And we're going to say something like damage.
Uh, or we can say uh call call info, dot GameObject, dot name and top of that I'm going to add a
custom message.
So use this plus icon then and this quotation.
And you can just put a custom message that you want to see underneath your console tab.
I'm going to say something like takes damage, takes damage, and let's close that up with semicolon.
So call info dot GameObject basically means the GameObject the circle collided with.
So in our case call info dot GameObject gonna be this player game object.
Because the circle that we created, it's gonna collide with this player game object.
So call info dot GameObject.
There basically means this player game object.
And then what we're doing accessing the name.
And we can see the name is player.
As you can notice in the Inspector.
So this right over here we're calling for dot GameObject dot name.
Basically just gonna be player.
And top of that we just added a message text damage.
So the so this message just gonna pop up says player takes damage.
So this message just going to pop up as soon as the circle just gonna collide with that player game
object.
So now what we're gonna do.
We're gonna press down Ctrl s to save our skin.
And now let's move over to unity.
And also we need to do one more scripting.
Basically we need to add some line of code in order to see the circle that we created from that attack
point from inside our enemy GameObject.
Let me show you.
Uh, so we do know that the circle will not be drawn.
So we need to draw that with uh using on draw smooth selected function.
And we're going to do the same thing as we have done inside our player shape.
We will, uh, we will do in a same way.
So just wait a moment, uh, to compile our script.
Now it's done.
And if we select our enemy to GameObject and press down F in order to focus on that.
Sorry, I don't know.
The enemy two script should be sorry, I really apologize.
So this should be enemy two.
Sorry.
Enemy two.
As you can notice that the circle will not able to see that we created.
And in order to see that, we do know that we need to use a function called on draw gizmo selected.
So let's open up our animator script by double clicking on it.
And let's go over to our on draw mode selected function right over here.
So we're gonna draw that.
But before we draw we need to check.
Basically we need to check that if we drag this attack point to attack point slot or not, if we if
we haven't drag it, then we need to stop drawing drawing that circle because we don't have the attack
point.
So that's why.
So before we draw the circle we just want to check.
So we're going to use this if condition.
Let's make first bracket and some curly brackets.
And what we want to check over here.
We basically want to check if our attack point if it's not equal to null.
Not equal to null basically means that attack point we just drag it.
So if you just drag it like this basically means attack point is not empty.
It's we just assign it with attack point.
And this attack point not equal to null basically means we just assign it our attack point.
So now we have the attack point.
And now we are ready to create the circle or to create.
Sorry to draw the circle.
So what we're going to do now we're going to draw the circle.
And in order to draw that we're going to use this gizmos dot draw.
Sorry draw where sphere function, this function and this function as a first argument.
It's going to take the point from where we want to draw the circle.
So we're going to pass our attack point dot position.
And the second thing it's going to take the radius.
So we will pass our attack radius.
And let's close that up with semicolon.
And I also want to assign the color that I would like to draw with.
So to choose the color we before we draw we're going to use this gizmos dot color.
And we can set the color that we would like to draw with.
So I'm going to draw with yellow.
So I'm going to pass color dot yellow sorry Color dot.
Dot yellow.
And then close that up with semicolon.
So firstly we're checking if we assign it a tag point or not.
Basically means a attack point fill is not empty.
Basically we assign it attack point.
So then we just choosing a color.
And that color we just drawing our circle from this attack point.
With this much of radius as you can notice.
And now what we have to do, we need to press down Ctrl s in order to save our script.
And now let's move over to unity.
So as soon as our script just gonna compile, you will be able to notice from that attack point, that
circle just gonna draw and the circle will be draw with this much of radius, which we by default we
have given one, but we can just play around with the number and we just need to fit it perfectly with
our attack animation.
So we need to choose our attack animation.
And now we can see the circle just drawn from this attack point.
And we need to adjust this attack point in order to in order to cover up the attack range of this animation
attack animation.
So we will select our animator GameObject in the hierarchy.
Then go over to animation tab and let's click over here.
And we will check.
We will choose our enemy to attack Animation Clip.
And let's move it somewhere around here.
So as you can see we need to fill this out.
So that's why we're going to increase our attack radius.
So we will select our animator GameObject in the hierarchy.
Then go over to Inspector, then Animator Script.
In the bottom we have the attack radius.
So let's bump up the value.
So we're going to do something around I guess two uh, to just uh, just a perfect number as you can
see.
So that is fine by now.
So we're going to move over to overrides and then apply all.
So the changes we made it's going to be safe.
And now let's select our console tab.
And let's click on this play button in the top in order to play our game.
So as soon as the circle just gonna collide with this player game object, that message should be pop
up.
Says player takes damage, but it's not gonna pop up at all.
Why?
Because we just created that attack function and we never calling it anywhere.
So that's why, even though we're gonna take damage from this enemy to game object, we can notice that
the message is not getting pop up underneath our console tab.
Why?
Because we just made the attack function and we never calling it.
So I'm gonna get out of play mode.
And if we move over to our enemy two script and move over to our attack function over here, as you
can see, we just created this function and we never calling it.
So that's why it's not creating that circle around from around from that attack position.
So what we need to do, we need to call this attack function.
But when we need to call it once the the this enemy two game object just gonna play the attack animation
clip.
So we will select our enemy two game object.
Let's move over to animation tab.
And we're going to choose our attack animation.
And let's move over some some frames something like this.
So this is going to be perfect time.
So we can call the function over here in this moment.
So that moment the circle will be created.
And if the circle collide with this player game object then the message just going to pop up says player
takes damage.
So we need to call the function.
And in order to call the function we do know in animation tab in the left side basically over right
over here in the right side assess it add event.
So we need to click on it.
Then select this event.
Then go over to Inspector.
As you can see function.
And it says no function selected.
So just click there and then go over to anime anime two script.
Then methods you can simply say functions.
And we created the attack function there.
So we're going to choose that attack function.
Now we're just calling the attack function.
And we do know what attack function is really doing.
It's basically creating the circle from this attack point with the attack radius amount.
So now that's perfect.
So what we're simply doing we're just going over to this Army two script.
As you can notice right over here.
And from here we're just calling this attack function and attack function basically doing these things,
creating the circle.
And before the circle collide with that enemy game object or not.
Basically we're just checking if the player script is attached to that player game object or not.
If it's not equal to null means the player script is sitting on our player game object, and if we select
our player game object in the hierarchy, then go over to Inspector and we can notice that player script
is sitting on this player game object.
Then what we're doing, we just simply printing out this message says a player takes damage.
As you can see, player takes damage message just gonna pop up.
So not equal to null basically means the script is attached to that GameObject or the component attached
to that GameObject.
And now we're going to press Down control S one more time to save our script.
If we have done anything any changes.
And now we already chosen the function.
So I'm going to select my console tab.
And let's click on this play button in the top in order to play our game.
And now let's take a look on this.
So as soon as this animator GameObject just going to play the Attack animation clip, in that moment
we're calling the attack function.
And we do know what that attack function is really doing.
It's basically just uh, we can see by now, and indeed we can see if we move over to our console tab,
we can see a message just getting pop up.
Says player takes damage.
So instead of printing out message, we want to damage our basically this player game object.
And we're going to take a look on this later.
So we will leave as it is.
Like this message should be pop up.
And later on we're gonna we're gonna do the scripting thing.
Firstly, we need to give some health amount to our player game object and we're gonna take a look on
it later.
So I'm going to get out of play mode.
So I hope you get the idea that how you can do it.
I hope you get the idea that how you can do it.
And also we need to do one thing that we need to, uh, we need to basically we need to, uh, pop up
some values, uh, or floating numbers, as we have done with enemy one game object.
So this one will be a task for you to do that.
So you can do it.
You can just follow the same way as we have done inside this enemy one game object.
Uh, so once this enemy two game object just gonna takes damage from our player game object, then this
enemy two from this head, it should pop up that floating text number, something like 100, sometimes
80, sometimes 99, sometimes 100, and sometimes one.
And we do know we already have done it inside our enemy one game object.
So this will be a little small task for you to do that inside this Army two game object inside your
anime two script.
So you can just follow the same thing.
Uh, or you can just paste your, uh, you can just copy your code from your first anime, then you
can just paste it over, uh, on on top of this anime two script or inside this anime.
Two, uh, script, you can simply say, I hope you get the idea by now.
And I'm gonna press down Ctrl s on my keyboard to save my project.
And also make sure you select your anime two game object, then go over to Inspector Overrides and then
apply all.
If you just made this anime two game object a prefab, if you have done it, then you just need to go
to Inspector Overrides and then apply all.
So I hope you get the idea that how you can do it.
And you enjoyed this, uh, lecture.
So we're gonna take some look in the next lecture.