Let's create our second anime.
For now, I'm just gonna disable this first anime.
So I will select my anime one game object in the hierarchy and let's go to Inspector.
You can just uncheck in order to disable.
And if you just want to enable then you can just check there.
But I'm gonna disable it for now.
So I'm gonna uncheck that and let's create the second anime.
To do so let's move over to project tab assets and then sprites folder I have A3 folder where I have
the second anime.
So I'm going to choose that.
So I have a skeleton sprite as you can see.
So I'm going to select all of this sprite by holding down shift.
Let's go to Inspector.
And I'm going to make this pixel per unit to something like 16 and filter mode to point filter to just
get rid of blurry.
And after doing all of this thing click on this apply and we're going to find the ideal sprite of this
skeleton anime.
So let's select the ideal sprite sheet from.
Let's choose the ideal one.
So work.
And this one is ideal.
So let's select that.
Go over to Inspector and let's click on this open Sprite editor.
So we can see we have multiple enemies.
So we need to split individually.
So let's go to Sprite Editor tab.
Let's click on this slice.
And we're going to select Grid by Cell count.
And let's count how many columns and rows it has.
So 36678.
So we're going to put eight columns and one row.
Let's click on slice Apply.
And we're also going to find the attack one.
So I have this sprite sheet which is the attack one.
Let's slice as well this one.
So we need to count first.
So 489 ten I guess ten columns.
So we're going to put around ten columns and one row.
Let's click on this slice and then click on apply.
And what we need to do now let's select the game view once again over here.
And let's select the ideal sprite.
So I'm going to choose the ideal one.
So we have it here.
So let's click on this arrow in order to see the individual sprites.
And I'm going to select my first one.
And let's drag it over to this scene view or into the hierarchy.
And what I want to do I just want to make it a little bit bigger basically this anime.
So I'm going to make the pixel per unit a bigger number.
So I'm going to select all of them.
And I'm going to make this pixel per unit something like 12.
And now let's click on this apply.
And now we can see it's a little bit bigger.
So I.
I'm gonna name it to something like anime two.
Let's call it anime two.
And we also need to flip this anime to the left direction.
To do so let's go to Sprite Renderer component, and we're going to check this flip in the x axis or
horizontally.
And let's add some components to this anime.
Game object.
Anime two game object.
Firstly, we're going to add a box collider 2D for collision detection.
Let's add the rigid body first.
So let's click on this add component and we're going to add the rigid body 2D for gravity.
And I'm going to increase my gravity something around three collision detection.
We're going to choose continuous and make sure you just freeze the rotation in the z axis.
Or it's going to rotate like uh weirdly.
So that's why.
And now let's add a box collider 2D for collision detection.
So let's click on this add component.
And we're gonna add a box Collider 2D.
And let's add adjust the collider as the size of our anime two game object or as the size of our skeleton.
So let's click on this Edit Collider.
And we're going to edit the collider as the size of our, uh, this skeleton game object.
And now it's fine.
And we also need to create the animation, uh, animation as well.
So uh, we're going to create that.
But before it, let's create a script in order to attack on this player game object.
So let's do that.
So for that we're going to move over to project app, then Assets folder and then head over to this
script folder.
Let's right click there create and then Monobehaviour script.
And you can name that script to something like animator.
I already have created a anime script, as you can see over here.
So we need to attach this script to our anime to GameObject in the hierarchy.
So let's select the animator GameObject in the hierarchy, and let's select this script and drag it
over to this Add Component section in the Inspector.
And we're gonna open that up by quickly.
And what we're gonna do now, uh, firstly we need a reference to our player game object uh, or player
transform means position.
So we can just keep track of where player is.
And also we're gonna define a attack range in this enemy script.
Enemy two script.
Uh, in order to attack on this player game object, and if this player just comes in attack range,
then then this army need to attack on our player game object.
So basically that is the thing.
So let's open up our animator script and let's go to top of our class.
And we need to gather those variable.
First thing we need our player transform means player position.
So let's make a public transform.
You can simply say this transform is responsible for position and we have to name it.
So we can simply call it player position.
Or I'm going to call it simply player.
And the second thing we need a attack range.
So let's define that as well.
So I'm going to make another public float.
And we can call this one to something like attack radius or attack range as well.
So I'm going to call it attack range.
And by default I'm going to set around something like four F or four unit.
And we need a more things.
Uh, but before we do, let's save our script and then move over to unity because we need to assign
those variables one by one.
Firstly, we're going to able to see our player transform.
So we need to drag the player game object in that slot.
Basically we need the player transform.
Or you can simply say the player position.
So just wait for to compile.
And once it's done we need to drag all of those things.
So now as soon as player sorry animator script gets compiled, we can see player and it says transform.
So let's select the player game object in the hierarchy and drag it right there.
Now we can see player transform.
We have the reference means player position.
So let's open up our script.
So what we basically want to do we're going to create a circle around this uh, around uh, this uh,
skeleton game object or this enemy two game object.
And if this player game object comes in or just collide with that circle, then this enemy game object,
uh, this enemy two game object needs to attack on our player game object.
So we're gonna do that.
We're going to create a circle around this enemy two or this enemy, uh, sorry, skeleton game object.
And if this player game object get inside, then this enemy two game object or this skeleton need to
attack on our player.
So we're gonna do that.
But before we do, let's make sure you just, uh.
And make that this enemy two as well as a prefab.
So we're gonna have the copy.
So let's select the animator GameObject in the hierarchy, and let's drag it over to this prefabs folder.
And now we just turn it into a prefab.
And let's open up the script by now by double clicking on it.
So we're gonna move over to this update function.
And we do know that update function runs every single frame.
So every single frame we're going to keep track of.
So we're going to create the circle.
And in order to create the circle we need to use this physics 2D dot overlap circle overlap circle.
And this over here as a first argument, it's going to take the position from where you want to create
the circle.
So this physics 2D overlap circle will just create the circle around our enemy game object.
So we just want to create the circle.
And on this enemy GameObject center position.
So as a first argument it's going to take the position from where we want to create.
So we're going to pass this Transform.position Transform.position basically means current position or
center position our enemy game object.
And the second thing comma, it's going to take the radius with how much radius you just want to create
the circle.
So we're going to create the circle around this much radius or this much of attack range.
As you can see we created.
So we're going to pass this as a second argument which is attack range attack range.
And by default we set four.
So the circle will be drawn from this.
Or just going to create from this enemy GameObject center position with this matchup attack range radius
which is for unit.
And the third argument we need the layer mask or which game object basically we want to deal with.
So we'll deal with this player game object.
And we're gonna only check for this player game object.
If this player game object comes in attack range of this enemy game object, you can simply say then
this enemy game object need to attack on this player game object.
So we're gonna only check gonna check for this player.
So we need the layer mask.
So let's go to top of our class.
And let's define a layer mask as well.
Basically which game object we simply want to target.
So let's create a public that will be layer mask.
And we can call this one to something like target layer or attack layer.
I'm going to call it something like Target Layer.
And let's close that up with semicolon.
As a third argument over here we're going to pass the target layer.
And let's close that up with semicolon.
So now what we have to do.
Let's save our script first.
And let's move to unity because we need to assign those variable by one by one.
So as a layer mask or target layer we created, we can choose this layer.
But before you choose player make sure you assign your player game object as a player layer.
So now we gonna able to see.
As you can see, as soon as enemy two script gets compile target layer and it says nothing.
So we're going to choose the player.
But before you do, make sure you select your player game object in the hierarchy and in the inspector
top right you can see layer and it will be default.
So just click there and then click on this add layer.
And you have to name the layer what you want to name it.
So you can name it something like player and make sure you just go.
Also go back to that game object one more time, then go over to Inspector and the layer.
It will be default.
So you can just select the the which one you recently created.
So you just assign with that and it's going to be fine.
And now what we're going to do as a target layer and it says nothing.
So I only want to check for this player game object.
So I'm going to choose the player over here.
Or I only want to damage this player game object.
So that's why as a target layer or layer pass, we have chosen this player.
You can choose multiple layers as well.
Or if you have, if you just want to damage multiple things, then you can choose that.
But I'm going to choose this player only for now and let's go to script.
So this just going to create the circle around our enemy position, center position with this much of
radius which is attack range and target layer.
So as a target layer we already have chosen our player game object.
So the circle only going to check for our player game object.
So this over here it's going to return us to true or false depending upon if this player game object
really collide with that circle, then this function over here, it's going to give us a true value
as it will give us a false value.
So what we will do, we're going to store the result into a collider 2D because this is gonna work like
as a collision.
So we need to store the result into a collider 2D variable.
So let's put it over here.
So we're going to create a collider 2D variable.
And we can call this one to something like call info.
Or you can simply say call information collision information.
And let's set equal to this.
So this this can be true or false depending upon the circle is really colliding with the player game
object or not.
If it's then it's going to be true.
So we are storing that result into this call info means this call info is going to be true right away
if the circle is really colliding with that player game object.
So we're going to check in the next line.
We will check if and make first bracket some curly brackets and what we want to check over here.
We're going to check this call.
Info is equals equals to true.
Or you can just leave it like this.
It's also basically means true means our player game object really are colliding with the enemy game
object circle.
So what it's need to do now?
This anime game object need to, uh, attack on this player game object by now.
Uh, so.
So for now, let's print out a message.
Uh, if it's perfectly working or not.
So we're going to type debug dot log in order to print out a message.
And over here what we're going to do, we're going to use this call information parameter in order to
extract info what we collided with.
So we storing all of the information.
Basically the result into this call info call info parameter.
And we can use this parameter in order to extract all of the things that we want to, uh, do.
Something like we can extract info.
The name of the game object the circle collided with the tag of the game object, or any component that
we looking for.
So we're going to print out the name of the game object the circle collided with.
So we're going to use we're going to take this call info parameter in order to extract information.
So we're going to go to call info and then dot GameObject, dot name and top of that I'm going to add
a custom message.
So let's use this plus icon and some quotation.
And I'm going to say something like uh.
The takes damage or in attack range.
And let's close that up with semicolon.
So what we basically have done over here, we're just using this call info parameter in order to extract
info, uh extract the name.
So call info dot GameObject basically means the GameObject the circle collided with.
So the circle will be created from this enemy GameObject.
And if this player GameObject collide with that circle, then what we're doing, we just using that
call info parameter and we just extracting information about the GameObject we collided with.
So the circle definitely gonna collide with this player game object.
So what we're doing we're just going over to this player game object.
And then we just accessing the name so we can see in the inspector the name is player.
So this call info dot GameObject dot name basically means uh, it will be a player, uh, the name and
top of that we just added a custom message says in attack range.
So this should be a player in attack range.
So this message just gonna pop up underneath our console tab.
So I'm going to press down Ctrl S to save our script.
And let's move to unity by now.
And we need to select our console in order to see that.
So just wait for to compile.
Uh, but, uh, the problem is that we're not able to see our circle.
It would be nice if we able to see our circle as well, so we can just, uh, get a visual appealing.
So let's open up our script one more time.
And we do know we need to use a function on draw gizmo selected in order to draw something.
So we're going to do it over here on sorry on draw gizmo more selected and make sure users typing as
I did over here.
Else it not gonna be, uh, not gonna work.
Because this is unity.
Callback function means it's gonna call by unity automatically.
You don't need to call this function anywhere else.
So in order to, uh, draw a circle, we need to use this gizmos dot draw where sphere function.
And this over here as a first argument, it's going to take the position from where we want to draw.
So we're going to draw the transform dot position or basically center position of our enemy.
Second thing comma it's going to take the radius.
And we're going to draw the circle around this much of attack range.
As you can see with this much of attack range radius.
So as the second argument we're going to pass this attack range attack range uh as a radius.
And then we're going to close that up with semicolon.
And if you want to choose a different color then you can just go up and you can choose the color as
well before you draw the circle.
So we're going to use this gizmos.
Sorry.
Uh, gizmos.
Gizmos.
Dot dot color.
And you can set equal to any color that you would like to go with.
So I'm going to say something like color dot yellow.
I will use in order to draw my circle.
And let's close that up with semicolon.
And let's press down control S in order to save our script.
And let's move to unity.
So we will see as soon as the script is going to get compiled, we will see the circle will be drawn
from this enemy GameObject center position, uh, from this enemy two.
So just wait.
And uh, if we select our enemy two.
As you can see now, the circle has been drawn, so we can just increase the radius of this circle as
well.
So I'm going to make the attack range something like 5.5 something like that something around that.
And let's go to Overrides and Inspector let's click on this apply all.
And I'm going to move this uh, anime game object a little bit down somewhere over here, and I'm going
to select my console tab, and let's click on this play button in the top in order to see the message
in the console.
So just wait.
And once it's done, we are ready to go inside the circle of this anime to game object.
And as soon as we're gonna collide, that message should pop up right away.
So let's, uh, have a look on this.
As you can see, as soon as we get inside of that circle, a message just getting pop up in the console
says player in attack range.
So let's get out of play mode.
And instead of, uh, basically printing out that we need to basically this anime game enemy to game
object need to play the attack animation.
Uh, it's need to play the attack animation.
So this player game object just gonna take the damage right away.
So I hope you get the idea that how you can just, uh, do it, you can, uh, do with anything like
that, and that's.
It's pretty cool.