Now let's do the same thing with our heart.
So for that, I'm going to move over to my project tab assets and then the sprites folder and then coin
and hearts folder.
I have, as you can notice right over here I have the heart.
So I'm going to select that sprite sheet.
Let's go over to Inspector.
Let's click on this open Sprite editor.
So we're going to slice individually.
So sprite mode to multiple and pixel per unit.
I'm going to make it something around 16 and filter mode to point no filter to get rid of blurry.
And then click on this apply button in the bottom right.
And let's go over to Sprite Editor tab.
Let's click on this slice and let's select automatic to Create by Cell count.
And let's count how many columns and rows we have.
So we have one row and for eight columns.
So we're going to put eight columns and one row.
And then click on slice and then apply.
And I'm going to select my game view once again.
And let's go move over to that sprite sheet and then click on this arrow in order to see the individual.
So I'm going to select the first one.
Let's drag it over to this scene view or into this hierarchy.
As you can notice it's kind of seem a little bit small.
So we just want to make it a little bit bigger.
So we need to make we need to make our pixel per unit number less.
So I'm going to select that spreadsheet one more time.
Let's go over to Inspector and Pixel per unit.
I'm going to choose something around 12.
And then let's click on this apply button in the bottom.
Still it seems a little bit small.
So I'm gonna do it ten.
And now let's click on this apply button.
Now say ten seems pretty much fine number.
And we're going to do the same things.
Basically we will create an empty parent game object first.
And we're going to make this sprite, basically this sprite child of that game object.
So our animation just gonna because we're gonna have two animation clip which will be collected one
and the other one will be the you can simply say ideal animation of this, uh, heart sprite.
Uh, basically, we're doing the same thing as we have done with this fruit.
Or you can simply say with this Apple game object, so let's rename this sprite or this sprite to something
like heart heart icon.
So let's call it something like heart uh, heart sprite.
Or we can simply say, uh, let's call it heart sprite instead of heart icon.
And now we're going to create an empty game object.
To do that, let's move over to hierarchy.
Right click or hit this plus icon.
Let's create an empty game object.
And we're gonna call this game object to something like heart.
And if you want to choose an gizmos then go over to Inspector.
Click here.
And I'm going to choose this gizmo.
And now what we're going to do, we're going to take our sprite in the hierarchy.
And let's drag it over to this heart GameObject, top of this heart game object in the hierarchy.
Then select your hardware sprite basically the child one.
Then go over to Inspector.
Right click on this transform and then reset.
As you can see it, just reset the position as the position of our heart game object.
So now if I take my heart GameObject in the hierarchy, basically select that and try to move around.
As you can notice with that our heart sprite is also moving.
So basically that is the thing we just done.
And I'm going to select my heart GameObject.
Let's drag it in the top so we can see all the time.
And we will add some components.
So first thing we're going to add a rigid body 2D.
And we will set it to kinematic.
So it's not going to fall down at all.
So let's go over to Inspector.
Let's click on this add component and we're going to add Rigidbody 2D.
And let's attach that.
Let's go over to Rigidbody 2D.
And let's set the body type to kinematic.
So it's not going to fall down.
And collision detection to continuous and interpolate to interpolate to making smooth.
And we will add second thing which will be a polygon Collider 2D or any Collider 2D, something like
that.
And it should fit perfectly.
So that's why.
So I'm going to click on this add component.
Make sure you do these things with the parent, not the child one inside the child one.
We just want to make the animation only and into this parent game object.
We're just going to add the components.
So let's click on this add component.
Now let's add up a polygon Collider 2D or a Circle Collider 2D.
But I'm going to add a Polygon Collider to it to just fit perfectly.
So let's find it by typing Polygon Collider 2D and then attach.
And then let's click on this Edit Collider.
And we're going to edit the Collider as the size of our hard GameObject hard sprite, you can simply
say and we're going to drag it like this.
And this seems pretty much fine.
You can simply say and let's drag it here.
And this seems much fine, as you can notice.
So that's why we just added Polygon Collider 2D instead of Circle Collider 2D to just feed it perfectly.
And once you are done, make sure you just go over to your Polygon Collider 2D or Collider 2D you recently
added and check this is trigger.
So it's not gonna register our player to pass through it.
And we're gonna use Ontriggerenter 2D function in order to check the trigger.
If we just trigger it with this hard GameObject or not.
So we're going to assign this heart as a heart game object as a heart tag.
To do so, let's go over to Inspector.
Make sure you select the parent one in the hierarchy.
Then go over to Inspector.
Click on untag.
Let's click on Add Tag and we're going to create a new tag for our heart.
So let's click on this plus icon.
And we're going to name this to something like heart.
And then click on the save button.
And we're going to select our heart GameObject in the hierarchy, basically the parent, and then go
over to its Inspector and assign with the tag you recently created.
So I'm going to assign my heart GameObject as a heart attack.
As you can notice.
So we just made it.
Now let's make the animation of this heart game object.
To do that, we're going to select our heart sprite.
Basically the child one, not the parent one to parent one.
So make sure you select the child one instead of the parent one.
Then go over to project tab assets.
And then I'm going to move over to my sprites folder.
Then Coins and Hearts folder where basically I have the sprite sheet.
And then we're going to select all of these by holding down shift, and then drag it over to this sprite
game object.
Basically the child one, top of this child one in the hierarchy.
And it's going to take us, take us to a folder where we want to place it.
So we will go to assets and assets.
We created this animation folder as you can notice.
we're gonna open that up by double clicking on it.
And let's move over to items animation folder.
And we have to name the animation clip.
So this will be hard.
Idle.
So I'm going to call it heart underscore idle.
And let's click on the save button.
And then if we select our hardest part then go over to animation tab.
And then click on this play button.
As you can notice is playing the idle animation clip or basically the heart sprite animation or the
Heart Idle animation clip.
And we need to create the second clip, which are basically these are just going to go up and over time
it's going to fade out, as we have done with this fruit game object.
Or you can simply say with this Apple game object.
So we're going to do the same thing.
So let's select our sprite.
Let's go over to animation tab and let's click here.
And let's click on this Create New clip.
And we have to name we have to name the clip or the animation, so this will be hard.
Underscore something like collect one.
So we're going to call this one collect it.
So let's call it collect it.
And then click on the save button.
And now what we're going to do we're going to make the animation.
So let's click on this red button in order to capture the animation.
And let's move it over to 60 frame.
And then let's select the sprite underneath our hard GameObject in the hierarchy.
And let's drag it in the up direction.
And over time it should fade out.
To do that, let's go over to Inspector Sprite Renderer Component and let's click on this color.
And in the bottom a we can see 255.
So let's make it zero.
So it's gonna fade out.
And now if we click on this play button as you can see it's going up.
And over time it's just fading out.
And once we are satisfied then we can just click on this red button to capture the animation.
Or we can just leave it like that.
It's automatically gonna capture the animation.
So I hope you get the idea by now.
And if we select our sprite GameObject in the hierarchy underneath our hard GameObject, then go over
to animator tab as you can.
As you can notice, we have the heart underscore idle animation clip as well as heart Underscore collected.
So we need to make transition between this animation clip from this heart idle to heart collected.
So we need to make transition.
So let's click on right click on this heart idle and make transition to this heart collected.
And let's select this transition.
Go over to Inspector and we're going to uncheck.
This has exit time because as soon as we can collect this heart we want to play the heart collected
animation clip right away.
So that's why we just untick the has exit time as well as we'll set the transition to zero.
And if we scroll down, we need to choose a condition in which condition we want to play the animation
clip.
So for this heart a heart I'm gonna choose a trigger parameter.
To do that, let's move over to our animator tab and let's select this parameter.
Let's click on this plus icon.
And we're going to choose a trigger.
And we will call this trigger to something like collected.
And then we're going to choose this parameter.
So let's select this transition.
Go over to Inspector scroll down and then click on this condition.
And we're going to choose this collected.
And now that's fine.
And I don't want to play this hard collected animation clip over again and again.
So what we're gonna do we're going to uncheck the loop time of this hard collected animation clip uh
clip.
So we need to move over to our project tab assets and then animation folder.
Basically we need to move over to move over to that folder in which folder we just created the animation
clip.
So we have done inside this items animation folder as you can notice.
And we have the heart collected as well as the heart idle.
So I'm going to choose my heart underscore collected one.
Let's go over to Inspector and we're going to uncheck the loop time.
So it's not going to loop at all.
And if I select my heart GameObject in the hierarchy and move over to animator tab, basically select
this heart sprite and then click on this play button in the top.
In order to play our game.
You will notice as soon as our game just gonna start a heart idle animation.
Just gonna play right away.
Why?
Because that animation clip is the default one, so that is the reason.
So just wait a moment.
And as you can see, indeed it's playing the heart idle animation clip over again and again.
And if I trigger this collected parameter manually, you will notice this heart collected animation
just going to play right away.
As soon as we're gonna trigger with trigger this heart collected animation clip.
Basically this collected uh, parameter if we trigger it.
So if I just trigger manually, as you can notice, as soon as we trigger it, it just played that animation
clip.
So now we're going to get out of play mode.
And basically we have done the thing and now what we need to do, we need to make this hard game object
a prefab.
So we will have the copy of it.
So we're going to select our hard GameObject in the hierarchy.
And let's drag it over to this prefabs folder in order to turn it into a prefab.
So we're going to select our hard game object in the hierarchy.
And let's drag it over to this prefabs folder in our project app.
And let's create a sub folder for our collectibles.
Uh, this apple and this heart.
So let's do it.
So let's go over to project app first, then assets and then prefabs folder.
And let's create a sub folder for our collectibles item.
So let's right click then create a folder.
And we're going to call this folder to something like collectibles.
So let's call it collect uh collectables collectables.
And we're going to select our Apple and this heart.
And let's drag it inside that sub folder.
Now we just made it as you can notice.
So we just created this folder to just keep our project clean.
So that's why we just create folder and we drag the things that we need inside that folder to just keep
our project clean.
And I'm going to select my heart GameObject in the hierarchy by now.
And we're gonna drag it on top of this collectables game object, because we just created this game
object in order to keep our our hierarchy clean.
So that's why we just created a collectibles game object and we just made our this game object child
of that game object.
So we can just click here in our hierarchy to just collapse at once.
And it's gonna just make our, uh, project clean and the hierarchy as well.
And I'm gonna press down Ctrl s on my keyboard in order to save my project.
So I hope you get the idea that how you can just do it.
We have done the same thing as we have done with our apple or that fruit game object.