Let's, uh, create some traps.
Uh, traps in order to take damage.
So I'm going to move over to my sample scene or the scene in which scene we're playing our game.
So let's head over to this project tab, then assets and then scenes folder.
And I'm going to double click on this sample scene in order to move into that scene.
So I have some uh traps sprites and we can see.
So let's, uh, move over to this project tab, then assets and then sprites folder.
And I have traps folder over here.
And you can see we have the sprites of traps.
Of course I will have a link in the resources of this as well.
So you can go and check that out.
And I'm going to select my player game object in the hierarchy.
And let's press down F on our keyboard in order to focus on it.
And let's go to I'm going to select my this shuriken.
So let's select that and select that sprite sheet.
Then go over to Inspector.
Click on Open Sprite Editor so we can see we have more than one sprite.
So we need to choose this sprite mode to multiple in the inspector, and we're gonna choose a pixel
per unit, something around 16in order to make this, uh, shuriken or this short rap a little bit large
in size, in sprite size.
And to get rid of blurry, we will choose this point filter.
And after doing all of these things, click on this apply button in the bottom.
And as soon as we click apply now we can see the blurry is gone by now and we need to slice individually.
So we will move over to this sprite Sprite editor tab.
In the top left we can see slice.
So just click there and select automatic to create by cell count and count how many columns and rows
you have.
So we can see we have one row and 369 columns.
So we're going to put nine columns and one row.
Uh sorry not nine actually I guess eight columns.
So we have eight columns and one row.
And let's click on this slice and then click on this apply.
And I'm going to select my game view once again over here.
And let's go to that spreadsheet and then click on this arrow in order to see the individual one.
So I'm going to select my first one.
So let's select that sprite and let's drag it over to the scene view or in this hierarchy.
So I'm going to drag it over to my scene view.
And I just want to make it a this uh a little bit uh big.
So what I'm going to do, I'm going to select my sprite sheet.
Let's go to Inspector.
And I'm going to make this pixel per unit a less number, even more smaller than 16.
So this is just going to be big in size.
So I'm going to make it something around 12.
And let's click on this apply button in the bottom.
As soon as we clicked apply we can see by now it's just gets a little bit bigger.
And I'm gonna call I'm gonna say something like uh shuriken.
So I'm going to call it shuriken.
And let's select this and I'm going to drag it top of my hierarchy in the hierarchy so I can see all
the time.
And we will add some components to this story.
First thing we will add a rigidbody 2D and we will set the gravity scale to zero.
Or we will set it to kinematic.
So it's not gonna fall down due to gravity.
And the second thing I will add a collider 2D to this origin.
So it's gonna detect collision.
If this player GameObject collide with this origin, that means our player GameObject need to destroy
right away.
So let's select this origin and let's add some component.
So let's click on this add component.
First thing I'm gonna add a rigid body 2D.
So let's find that component by typing.
And let's hit enter in order to attach that.
And I will set body type to kinematic.
So it's not gonna fall down.
Due to our gravity and collision detection.
We will choose continuous and interpolate.
We will choose interpolate to making a little bit smooth.
And we will add a second thing which is which will be a collider 2D for collision detection.
So let's click on this add component.
And we're going to add a Collider 2D.
So you can add any Collider 2D that you like.
You can go with this box Collider 2D as well as Circle Collider 2D.
But make sure it just fit perfectly.
So that's why we're gonna add a Circle Collider 2D in order to fit it perfectly.
And you can just adjust the radius of this Collider 2D as well by moving over to this radius.
And you can make something around 1.25.
And I'm going to make 1.25.
So this seems pretty much cool to me.
But you can just play around with that.
And I also want to assign this shuriken game object as a drop tag.
So we can see in the inspector tag it says untagged.
So just click there and then click on this add tag.
And we're going to click on this plus icon.
And we will create another tag for this trap.
So I will just going to add we're going to assign this as a this shuriken as a trap tag because I want
to check what we collided with.
If that came out say has a trap tag.
Proptech.
That means we need to destroy our player game object right away.
So that's why I'm going to assign this shuriken as a drop tag.
So let's call it drop and then click on save and make sure you just select that game object one more
time in the hierarchy.
Then go over to Inspector Tag.
It says untagged.
So let's click there and we're going to assign it with drop.
Now we assign it this shuriken as a drop tag so we can just uh no.
And also we need to make the animation, which is just gonna play the circular animation.
It's gonna seems like it's just rotating.
So I'm gonna move over to my project app one more time than assets, and then this, uh, drops folder
and I will select all of these individual sprite by holding down shift and then drag it over to the
shuriken GameObject in the hierarchy.
A hierarchy.
So it's going to make the animation right away.
So we will move over to this assets folder, then animation folder.
And we will move over to this stop animation folder.
And we will create another sub folder for Forth is a trap game object.
So let's right click the new folder and I will name this folder to something like traps animation and
traps.
Traps underscore animation.
So let's call it something like that and hit enter.
And we're going to double click on double click on it to in order to open that up.
And I will name this animation to something like shuriken.
So this is our shuriken or the shot trap.
So I'm going to name it to something like shuriken.
And after that click on the save button.
And now if we select our shuriken in the hierarchy then move over to animation tab.
We can click on this play button in order to see the animation.
And indeed it seems like it's just rotating.
So we just made the animation.
So let's code it.
But before we do, let's make this shuriken game object as well.
A prefab basically means copy.
So let's select the shuriken GameObject in the hierarchy, and let's drag it over to this assets folder
or into this prefab folder.
So I'm going to select my shuriken GameObject in the hierarchy, and I'm going to drag it over to my
this prefabs folder.
Now we just turn it into a prefab, basically a copy.
We have now.
So what we're going to do, we're going to check if this player GameObject collides with this shuriken
at this.
And in if this game object or this shuriken game object has a tag called trap.
And we do know that if we select our shuriken, we can see we assign it this shuriken game object as
a trap tag.
So I'm going to check that means if we if the player game object now collides with a trap tag, game
object means this player game object need to destroy right away.
So we're gonna go, we're gonna code it.
So let's select our player game object in the hierarchy.
And let's open up the player script where we just colliding.
So we're going to double click on this player script in order to open it up in Visual Studio.
And I will move over to my this on collision enter 2D.
So make sure you just type this and you can just ignore this if condition over here you can ignore it.
So make sure you just include this function.
This, uh, private void Oncollisionenter 2D function.
Basically, this function gets called when we collide with something.
So let's suppose this player GameObject collide with this shuriken GameObject.
Then this function over here.
Just gonna just gonna call right away and what we want to check.
And we're going to extract info info about this, what we hit with by moving over to this collision
parameter.
So we're going to use this collision argument over here we have on collision enter 2D function.
And by this parameter we can extract info about what we hit with.
So we can extract info like name of the game object we hit with the tag, even a component that we're
looking for.
So what I'm gonna do I'm going to check over here.
So this function get called when we collide with something.
And we we will check if we collide with that trap.
Uh, trap tag game object or not.
So I'm going to check.
So let's make this if condition first bracket and some curly brackets and what we want to check over
here.
We want to check whatever we collided with.
If that game object has a tag called trap.
So we will go to collision dot object dot tag and we will check if the tag is equals equals to trap.
If that is the case means uh, so basically what we're doing, we do know that once we collide with
this hurricane.
So this function is just going to call out right away.
And what we're doing we're checking if collision dot object dot tag collision dot game object basically
means the game object we collided with.
So we definitely gonna collide with this hurricane game object.
So collision game object right there basically means this hurricane game object.
And then what we're doing we're just going over to shuriken game object and accessing the tag.
And we're checking if the tag is equals equals to trap as you can see.
So basically we're just moving over to this shuriken game object once we collide then accessing the
tag and accessing the tag which is trap as you can see in the inspector.
And we're checking if the tag is equals.
Equals to trap tag.
As you can see over here means we definitely colliding with that.
So we can game object.
So what we need to do now we need to take damage.
So for now I'm going to print out a message in the console.
Firstly we just accessing the tag as you can see of that shuriken game object.
And then we're checking if the tag is equals equals to trap.
And we definitely know we assign it that game object as a trap tag.
So we're checking it over here means we just colliding with that.
So in that moment we need to destroy our player game object right away.
But before we destroy let's print out a message in the console, something like Destroy player.
So in order to print out message we're going to type debug dot log.
And we're going to say something like destroy destroy player.
And now let's close that up with semicolon.
And let's press down Ctrl S to save our script.
And let's move to unity by now.
So whenever we're going to collide with the shuriken GameObject, you will see that message just going
to pop up in the console says Destroy Player because we assign it this shuriken as a trap tag, and
we're checking right there if the tag is equals equals to trap or not.
If it's, then we're just printing out the message in the console says destroy player.
So I'm going to select my console tab.
And let's click on this play button in the top in order to check it and have a look.
And make sure you just make this shuriken GameObject as well a prefab so you can have the copy of it.
Then you can just, uh, place wherever you want.
So as you can see, as soon as we collided with this shuriken, I'm going to click on this pause button
in the top in order to pause my game.
And if we move over to console tab, we can see a message just gets pop up once we collide with the
shuriken GameObject and the message says Destroy Player.
So instead of printing out message what we really want to do, we just want to destroy this player game
object right away.
So when I click on this play button in the top in order to get out of play mode and let's move over
to script.
So instead of printing out message what we will do, we will destroy our player game object.
So what we will do, we're just going to call this type function.
And we already made a function inside this player script as you can see.
And what this function is doing, it's just activating the game over you by then, checking our camera,
then checking this, then showing up the explosion effect as you can see.
So it just doing all of the rest thing that we need to do.
So what we can simply do, we can simply call this type function and die function.
Just going to do all of these things like destroying our player and showing up, the showing up, the
explosion effect and camera check all of these things.
So we're going to call this type function.
And if you haven't met the die function yet then make it as basically create a custom function, call
it die, something like that.
And I'm going to call the function over here once we collide with the trap and we can see we're just
colliding over here.
So we will simply call that type function.
So we will make and we will put the name of the type function.
And let's make first bracket and close that up with semicolon.
Basically we're just calling that.
And now I'm going to press Ctrl s to save my script.
And let's move to unity.
So as soon as we're going to collide with this so we can game object, we will see that the function
just going to call out.
And we do know that what we have done inside that function, we basically destroying our player game
object and doing all of the rest thing that we need.
So I'm going to click on this play button in the top and we will see that.
So just wait a little moment to start our game.
Once it's done we are ready to do that.
So let's collide with this.
Uh, so again as you can see, as soon as we collided, uh, this game over us gets activated.
Camera just gets six as well as our.
We destroyed our player game object.
Basically what we really need to do, and we can just click on this retry button in order to load up
the level one more time or retry the game one more time.
So I'm going to click on this retry button.
And as soon as we just colliding with this hurricane, we're just destroying our player game object
right away as well as just we activating the game over UI.
And we can just click on this menu button in order to move over to Manu.
And we can just click on this play button in order to play our game.
So basically this is the cool thing.
And let's get out of play mode.
And we're going to have multiple uh traps as well.
I have also a fire trap.
And I'm going to drag this, uh, shuriken game object a little bit further away from this, uh, player
game object to testing for testing purposes only.
So I'm going to select my shuriken game object in the hierarchy, and let's select this move tool and
move tool over here.
And I'm going to move it something like this much because I'm going to have the fire trapped by now.
So I will move over to my project app one more time than assets and then sprites folder and traps folder.
I can see I have the fire trap over here, so let's select that.
Go over to Inspector, click on Open Sprite Editor.
So we need to slice it individually.
So we need to choose this sprite mode to multiple in Inspector and pixel per unit.
We're gonna make something around 16 as we have done our coin this heart and this shuriken.
For this shuriken we have chosen 12 but for this fire, I'm gonna choose it something around 16 and
to get rid of blurry, we're going to choose point no filter.
And let's click on this apply button.
And let's click on this slice.
In this Sprite Editor tab we will select automatic to create pixel count.
And let's count how many columns and rows we have.
So we have one row 369 12 columns.
So we're going to put 12 columns and one row.
And after that let's click on this slice and then click on this apply button and I'm going to select
my game view once again.
And let's go to that Fires sprite.
And let's click on this arrow in order to see the individual.
And I'm going to select my first one.
And let's select this one instead.
And I'm going to select that.
And let's drag it over to the scene view or in this hierarchy.
And I'm going to drag this GameObject in the hierarchy top.
So I can see all the time.
And I just want to rename this one to something like Fire Trap.
So let's call it Fire Trap.
And let's add some components to this fire trap as well.
So first thing we will add a rigid body 2D and we will set it to kinematic.
So it's not going to fall down due to our gravity.
So let's go to Inspector then let's click on this add component.
Let's add a component rigid body 2D.
And let's set the gravity body type to kinematic.
So it's not going to fall down due to gravity.
And we will choose collision detection to continuous.
So it will continuously detect any collision.
and also what we need to do.
We can just ignore this interpolate if you just want to make a.
If you just want to make a little a little bit smooth, then you can interpolate to interpolate.
But I'm going to leave that and let's add a one more collider to the component to this Firetrap game
object.
And that will be a collider 2D for collision detection.
So let's click on this add component and we will add a box Collider 2D.
And we will adjust the collider as the size of our sprite game object.
So let's click on this Edit Collider.
And we will edit the collider as the size of our sprite game object.
And you can see that as well.
And this this seems pretty fine now.
And also we want to assign this fire trap as a trap tag because this is our trap and we checking if
we're colliding with this trap then we just destroying our player game object.
So that's why we're going to assign this fire wire trap as well as a trap tag.
So let's go to Inspector then tag and it says untagged.
So let's assign with trap.
Now we so player can know this is our trap and this player game object need to destroy.
And I just want to edit the collider from the right side a little bit inside.
I just want it something like this much.
And this seems pretty much cool.
And once we are done, we can make this one fire trap a prefab in order to make it copy.
But before we do, let's make the animation.
So we will select all of the individual sprite by holding down shift of this fire trap.
And let's drag it over to this Fire Trap GameObject in the hierarchy in order to make the animation
right away.
So I will move over to my assets folder, then animation folder.
I have created this animation folder, so let's open that up.
And I also have traps underscore animation sub folder.
So let's open that up as well.
And I will call this animation to something like Fire trap, so let's call it fire instead.
And let's click on this save.
And if we select our Fire Trap GameObject in the hierarchy, then move over to the animation tab.
We can just click on this play button in order to see the animation.
Now as you can see.
So this seems pretty much cool.
And let's make this fire trap a prefab by now.
So I'm going to select my Fire Trap game object in the hierarchy, and let's drag it over to this prefabs
folder in our assets folder in this project tab.
Now we just made a prefab.
So if I just I'm going to move this one somewhere over here.
And let's click on this play button.
And you will see as soon as we're going to collide with this fire trap that we will destroy our player
game object, because we assigned this fire trap as a trap tag.
And we do know we just talking about it.
And as soon as we collide it, we can see we're just calling the die function and die function just
doing the right thing.
So I'm going to get out of play mode.
So what we basically have done, we just assign it this fire trap as a trap tag.
As you can see in Inspector and we do know which is only checking trap tag means if we just colliding
with any trap tag game object, we just calling the die function.
And you can notice over here as well if the game object has a tag called trap, and we do know we assign
it this shuriken as well as this fire trap as a trap tag.
So player, just knowing that this is our trap as well as well as this shuriken as a trap.
So that is the reason.
But the problem is that I don't want to activate this box.
Collider 2D once this fire stops are popping out from this thing.
So if I select my fire trap game object, then move over to animation tab and we can just move this
frame in order to see it.
So as you can see, edges are basically what we what it's basically doing.
It's just making our fire.
So I, I only want to activate this box Collider 2D of this Fire Trap GameObject.
Once it's just making out the fire out once it's just uh, you can say once the fire just getting activate.
So at that moment I'm going to enable this box collider to 2D.
But once, uh, the this file is not getting out, then I'm gonna disable this box Collider 2D so this
player GameObject can easily pass through it, or else we, uh, we will die as soon as we're gonna
collide with this, uh, fire.
So by default, I just want to deactivate this, uh, fire game.
Uh, this box Collider 2D of this fire trap game object.
So this player game object can easily pass through it.
But once this, uh, this thing just, uh, making our fire, then at that moment, I'm just gonna activate
this box Collider 2D.
So it will just gonna detect collision.
So basically that is the thing or the logic that we need to understand.
So by default, we're gonna disable this box Collider 2D.
We don't want this to be activate.
And once it's just making our file, then I'm gonna deactivate that file box.
Collider 2D.
So by default, we're gonna deactivate.
So let's select the file trap game object in the hierarchy.
Let's go to Inspector and I'm gonna uncheck this box Collider 2D.
Basically we just disabling it.
And now we're gonna move over to this animation tab of this fire trap.
And something over here, we're gonna we're gonna activate our box Collider 2D.
I guess this should be pretty much fine.
So what we can simply do, uh, we we're gonna activate the fire, uh, I guess over here.
So this are just gonna be perfect.
So in this moment, we need to activate that box.
Collider 2D because it just making our fire and this player game object.
If it's collide now, then we're just gonna destroy our player game object.
So let's go to animation tab and make sure you just hit this red button in order to capture the animation.
So in this moment we're gonna activate our box Collider 2D component.
So let's go to Inspector.
Then let's enable this box Collider 2D.
Or we just need to check in order to enable.
And over here we need to disable this something like over here we need to disable the box Collider 2D
because it's not making out fire at all in this moment.
So we're gonna disable that.
So let's go to Box Collider 2D and we will uncheck that.
So if we just make our if we just click on this play button in our animation tab we can see this box
Collider just getting activate once it's making our fire.
And once it's not making fire then it just we just deactivating the box.
Collider 2D.
So this player game object can easily pass through this time.
Once the box Collider 2D is disabled.
So that is the thing.
And I also want what I basically want to do.
I just want to move all of these frames a little bit further away.
So player gonna have enough time in order to pass through this file.
So basically that is the reason.
So make sure you just hit this red button to record your animation as it's not going to be recorded.
So make sure you just do that in animation tab.
And I'm going to select I think from this we're going to select all of this frame and let's drag it
away something like over here which is one second.
So we're gonna have enough time in order to pass through this fire trap.
And we can just click on this play button now so we can see we have a little bit time in order to deactivate
or activate this box.
Collider 2D.
So player gonna have the time that it can easily pass through this fire trap game object.
And once you are satisfied with the animation, then you can just hit this red button to capture the
animation.
Or you can just leave it like that.
It's automatically gonna capture the animation.
And let's have a look on this, and I'm gonna move my fire trap something over here and make sure you
just go to overrides in the inspector and then click on this apply all.
So this is fine by now.
And let's click on this play button in the top in order to see it.
And we're gonna have a look on it.
I hope you get the idea or the logic that we need to do so.
We basically need to move a little bit further away.
So we're gonna have a little bit time and we can see indeed once we just, uh, passes through that
fire trap once, uh, this fire just not making out.
So we just have the enough time.
I hope you get the idea.
And I'm gonna get out of play mode.
And also, we need to do one more thing is that once our player is, uh, down something over here,
it's not landing on top of this ground, and it just passes through it.
Something.
Let's suppose the player is over here.
Means player just gonna fall down.
Uh, to the.
You can see in the down direction, it means we need to destroy our player game object right away.
Once the player game object somewhere in the bottom over here.
Something like that.
So we can note the position as well.
So I'm going to select my player game object in the hierarchy.
So let's do it over here.
So let's select the player game object in the hierarchy.
And let's press down F in order to focus on it.
And we can just measure the y axis or the position that we're just going to call it die point.
So if I just move this player game object something in the Y somewhere over here.
So this position is just a perfect time in order to destroy this player game object.
Because as you can see, once the player is over here, it's not gonna make able to jump on top of this,
uh, tile gram.
So we need to destroy this player game object once.
It's just falling down somewhere over here in the Y, and we can just go over to Inspector, then transform.
And in the y axis, we can see the position which is minus, uh, I guess -1.8 just gonna be perfect
time or minus two simply.
So minus two we're going to check for.
So if the position of this player game object in the y axis minus two means we need to destroy this
player game object, because it's not going to be able to jump on top of that ground tile.
So that is the reason.
So let's do that.
So we're going to select our player game object in the hierarchy.
And let's open up the player script by double clicking on it.
And let's move over to our update function.
Over to this.
Because update function runs every single frame and every single frame.
We just want to check of our position, uh, check our position, uh, position of that player game
object.
So we're going to do it over here something like that.
So we will check if and let's make some curly brackets and what we want to check.
We just want to check y position of that player game object.
So we will check transform dot position dot y.
So transform dot position dot y basically means current position of that player game object in the y
axis.
So basically we're just going over to this uh Inspector sorry, we're moving over to this transform
of this player, then moving over to this position and accessing this y axis, as you can see.
And we will check y axis of that player game object if it's lesser than or equal to something like minus
two f as we check and we do know minus two f, just gonna be something over here means right now what
we need to do.
We need to destroy this player game object.
Because this player game object not gonna able to jump on top of this tile crown once the player game
object is over here in the y axis.
So what we will do in this situation we're going to call the die function.
And we do know what die function is doing.
It just destroying our player.
And we have the die function in the bottom as you can see.
So let's do that or let's call it over here.
Once our player position in the y axis is lesser than or equal to minus two f.
So let's call the die function over here.
And let's make first bracket.
Let's close that up with semicolon.
And we're going to press Ctrl S to save our script.
And let's move to unity.
So we're just taking our player position in the y axis, A or A or basically that means transform dot
position.
Dot y basically means current position of this player game object in the y axis y axis, and we are
checking if that is lesser than or equal to minus two.
F means we are just calling the die function and die function just doing the rest thing.
So let's go to unity now.
And I'm gonna move this player somewhere over here to check.
So in the y axis we're going to check.
So let's click on this play button in the top in order to check it.
And we will see once whenever this player game object in the y axis just gonna be uh, something like
-2 or 0.2, you will see this player game object just gonna destroy itself right away.
So just let's have a look on this.
Uh, so let's take a look.
So just wait a little bit moment, and we're going to check that.
Sorry.
uh, what I'm gonna do instead, I'm gonna.
I'm gonna select my player game object, and I will move this over here.
So this player game object just gonna just gonna fall right away for testing purposes.
I only have done it or just moved this player game object over here, and now we will check it.
So let's click on this play button in the top.
And as soon as this player game object in the y axis just gonna be lesser than or equal to minus two,
you will see this player game object just gonna die right away.
So let's see.
And as soon as the player game object is over here basically in the y axis which is minus two, we can
see, uh, our player game object dies and this game over UI just gets activated.
Basically we just calling the die function and die function just doing that thing.
So I'm gonna get out of play mode and I will move this player game object over here.
So let's select the player game object in the hierarchy.
And I'm gonna move it.
Something over here.
And this seems pretty much fine by now.