Let's create some collectible items.
So I'm going to create my heart first.
So let's go to project tab then assets folder and sprites folder.
And I'm going to move over to my UI folder.
I have this sprite as you can see.
Uh so firstly you need to select that uh basically select that go over to Inspector and then make this
pixel per unit to something around 16.
And then filter mode to point of filter to get rid of the blurry thing.
And after doing all of this thing click on this apply.
And what I'm going to do now I'm going to select my heart game object.
So let's click on this arrow and I'm going to select my heart.
Let's drag it over to this scene view.
As you can see we have the heart.
So what I'm going to do now firstly I'm going to create an empty parent game object.
And I'm going to make this heart sprite a child of that game object.
Why I'm going to create that.
Because we're going to have to animation in this heart sprite one will be which will go up and down,
uh, something like that.
Or it's basically just going to increase the size and over time the size will be decreased.
Basically I just want to make two animation.
So one will be the idol, which basically just gonna increase the size and decrease, and another one
just going to be the collected one.
Basically once our player game object collide with this heart.
So it's gonna go up and over time the sprite just gonna fade out.
So uh, collect something like collected animation clip.
So that's why we're gonna create an empty parent game object first, and then we're going to make this
one child of that, uh, to create, or else our animation just gonna be weird.
So that is the reason.
So let's go to hierarchy.
Right click or hit this plus icon.
Let's create an empty game object.
And I'm going to name this game object to something like heart uh heart.
And I'm gonna drag it this heart game object in top of my hierarchy.
And if you choose want to choose an eye gizmo.
So I'm going to choose this gizmo.
Something like this.
as you can see.
And now I'm going to select my sprite.
I'm going to know I'm going to call it to firstly hard sprite something like that.
So I'm going to call it hard sprite.
Sorry hard as sprite.
And now what I'm going to do I'm going to select my hard sprite and let's drag it over to this top of
this hard GameObject in the hierarchy.
And we're going to select our sprite.
Let's go to transform.
Let's right click and reset.
So it just reset the position as the position of our heart GameObject or the parent game object as you
can see.
So it just reset the position.
Now it seems fine and we are ready to create our animation.
But before I do I'm going to select my heart game object and I'm going to select my tool Move tool and
let's move it down somewhere over here.
As you can see, as soon as my moving our heart game object, the heart sprite is also moving with it.
Why?
Because this heart sprite is a child of our heart game object, as you can see in the hierarchy.
So that is the reason.
So let's make the animation by now.
So we're going to select our heart sprite basically not the parent heart sprite.
Let's select that.
Go over to animation tab.
And we are ready to create our animation.
So let's click on this create button and let's go to assets then animation folder.
And I'm going to move over to my animation folder.
And let's create another sub folder for this heart animation.
So let's right click New and Folder.
And I'm going to call this folder to something like heart animation.
So heart underscore animation.
And let's open up this folder as well by double clicking on it.
And we have to name the animation what we want to name it.
So I'm going to call this one to something like Heart Idol.
And we're going to have the another animation which will be the Heart Collected one.
So I'm going to name this animation to Heart Idol.
So this one just going to be the ideal one.
So let's click on that save.
And we are ready to create the The animation, so make sure you select the hardest sprite.
Then move over to animation tab and then click on this red button in order to record the animation.
So I'm gonna move over to my 30 frames, something like that in Timeline in Animation tab.
And then I'm gonna increase the size of this heart.
Something something around.
Uh, but before we do, I'm gonna get out of play mode.
So just click on this red button in order to get out of play mode.
So get out of play mode.
By default, I just want to decrease the size of the sprite.
I'm gonna make this one by default a little bit empty.
So let's select the sprite game object, uh, underneath our heart GameObject in the hierarchy.
Let's go to Inspector, and I'm going to make the scale in the X something like 0.5.
And in the y I'm going to make it around 0.5.
And now what I'm going to do.
And now I'm going to record the animation.
So let's select the sprite one more time.
Let's go to animation tab and then click on this red button.
And now we're gonna make our animation.
So I'm gonna move over to my 30 frame, something like that in animation tab.
Let's go to our inspector and make sure you select the heart sprite.
Then go to Inspector and transform.
And I'm gonna make the scale in the X, something like 1.2.
And in the Y I'm going to make it something like 1.2.
And now it's fine.
So if I just click on this play button, as you can see, animation is now playing over again and again
and once, uh, and now I'm gonna move over to 60 frame or this once again.
And I just want to set back this sprite size to, uh, the two back point five in the X as well as 0.5
in the Y.
So let's go to Inspector and I'm going to make in the X scale something like 0.5 once again back to
0.5.
So we're going to make in the Y as well as in the X 2.5.
So now if I just click on this play button in animation tab we can see the animation.
So the so the heart just increasing its size in the X as well as in the Y.
And over time it's just getting resized.
So it just resize and the animation is playing over again and again.
As you can see, animation seems now pretty much fine.
So you can just play around with this value so you can just move over to something like a two second
as well, or 120 frames.
You can just make spaces between these keyframe as well.
But I'm gonna leave it like this.
So let's click on this red button to capture the animation.
Or you can just leave it like that.
It's automatically gonna capture the animation.
So when I have the second animation.
So let's click over here in animation tab and let's click on this Create New clip.
And we have to name the clip what we want.
So this will be the collected one.
So I'm going to call this one heart underscore collected.
So we're going to call it heart underscore collected.
And let's click on this save.
And in this animation what I basically want to do.
So I'm going to move over to one second or a 60 frame, as you can see in animation tab.
But make sure you just hit this red button to capture the animation.
And I'm going to move over to one second or 60 frame.
And then I'm going to move this sprite in the up direction.
And over time I'm going to make this one fade out.
So let's select the sprite.
Let's go to Inspector.
And in the Y I'm going to increase the value.
Something around I guess this is fine.
And we can click on this play button in order to see.
So now as you can see this seems pretty much fine.
And also I just want to make this one fade out over time.
So let's go to a sprite renderer component then color.
Click there.
And in the A bottom you can see 255.
So we're going to make all the way to the zero.
Or you can just drag this line as well.
And now we can see it just fade out.
And we can click on this play button in order to see.
Now as you can see, this seems, uh, too much cool.
And I we created this animation clip by now.
So let's hit this red button to capture the animation.
And if we just click on this play button in the top, you will see that the animation just gonna play
and the heart uh, idle animation just gonna be the default one.
Why?
Because, uh, we just created that animation clip first, so that's why.
And we can see as soon as the game started at idle animation, it just playing over again and again,
and we can see, uh, that.
So if I select my heart sprite underneath my heart GameObject in the hierarchy, then move over to animator
tab, we can see heart idle animation is just playing over again and again.
So we also need to play this heart collected animation clip as well.
So let's get out of play mode.
And what we're gonna do now, uh, we're gonna move over to my animator tab.
So make sure you select the sprite GameObject in the hierarchy.
Then move over to this animator tab.
And let's right click on this Heart idol and make transition to heart collected.
And let's select this transition or arrow.
Let's go to Inspector.
And we're going to uncheck.
This has exit time because as soon as player collect this heart it should play the heart collected animation
clip immediately.
So that's why and we're going to set the transition duration to zero.
And if we scroll down we need to choose a trigger or a condition in which condition.
We just want to play that animation clip.
So we're going to set a condition for it.
So let's go to animator tab then parameters.
And let's click on this plus icon.
And we're going to choose a trigger.
And we're going to call this trigger to something like collected or Collide.
We can simply say a like that.
So I'm going to call it call it collide something like that.
Let's go to Inspector and we're going to click on this plus icon.
And we're going to choose this collide collide trigger.
So as soon as we're going to trigger this collide parameter you will see this heart collected animation.
Just going to play.
Why.
Because we have chosen that condition.
As you can see an inspector.
I guess I just misspelled my name.
I don't know what is the perfect spelling of this, but I really apologize for it.
Uh, so let's click on this play button in the top to have a look on this.
So if we try to trigger this collide parameter in animator tab manually, you will see this art collected
animation.
Just gonna play right away.
So let's trigger this parameter.
As you can see, as soon as we trigger the heart collected animation is now playing uh, and uh, it
just playing over again and again, as you can see.
And we don't want this animation clip to be looped, this heart collected.
So we're gonna get autoplay mode and let's go over to project tab then assets.
And we're gonna move over to that animation subfolder, uh, basically where we just created and saved
those animation clip of this heart game object.
So we're gonna move over to that sprite, uh, that animation, uh, that animation folder.
So in this heart sprite.
So let's go to stop animation.
And I have created this hurt underscore animation subfolder as you can see.
And we can see we have both of these animation clip which will we have hurt ideal as well as we have
hurt collected.
So I'm going to select my heart collected animation clip and let's go to Inspector.
And I'm going to uncheck the loop time.
So the animation not gonna be looped at all.
And I'm going to leave the heart idle because I want that animation clip to be played over again and
again.
So I'm not gonna uncheck the loop time.
And what we're going to do now we're gonna select our heart game object.
Basically select the parent one.
And we're gonna add Collider to this heart game object.
So player can easily detect collision detect collision.
And then we can just play the animation.
So I'm going to add some components to this heart game object.
So make sure you select the parent one not the child one.
So select the parent which in our case heart game object.
So we're going to select that.
Go over to Inspector.
Let's click on this add component and we're going to add a component.
First thing we're going to add a rigid body 2D.
And we're going to set the gravity scale to zero.
So it's not going to fall down due to our gravity.
So let's find rigid body 2D component.
And let's attach that.
And let's go over to rigid body 2D.
And I'm going to make the gravity scale to zero and collision detection.
We're going to choose continuous and interpolate.
We're going to choose interpolate to making a little bit smooth.
Or you can just ignore these things as well.
But make sure you just set the gravity scale to zero.
Or you can simply say simply set this body type to kinematic so it's not going to fall down due to gravity.
And we're going to add one more component which will be a collider 2D for our collision detection.
So this so this player GameObject can collect this heart game object.
So let's click on this add component.
And we're going to add a Polygon Collider 2D.
And you can add any type of Collider 2D you want but make sure it just fit perfectly our sprite size.
So let's click on this Edit Collider.
And we're going to edit the collider as the size of our sprite.
Uh, something like this much.
And this seems pretty much cool.
And we can simply to basically make this size the collider size as the size of your sprite.
And I'm going to I'm going to drag this up.
And now it seems fine.
And also make sure you just go to this polygon Collider or Collider 2D you attach, then move over to
trigger and check this box or else this, uh, this, uh, hard GameObject.
Just gonna register our player to pass through it.
So that's why we just, uh, check that trigger and we're going to assign this hard GameObject as a
heart attack.
So player.
So we can just detect, uh, detect the collision, and we can check also the name of the game object
or the tag of the game object the player collided with.
So that's why we're going to assign this hard game object with our hard tag.
So let's select the hard GameObject in the hierarchy.
Let's go over to Inspector and Tag.
As you can see it says untagged.
So just click there and then click on this add tag.
And let's click on this plus icon in order to add a tag.
And we're going to call this tag to something like heart something like that.
So let's call it heart.
And then click on save and make sure you select the game object one more time.
So in our case heart in the hierarchy.
Let's go to Inspector and Tag.
It says earn tag.
So let's click there and we're going to assign it with heart which we recently created.
Now we assign it this heart as a heart attack as you can see.
And we're going to make this heart game object a prefab.
So we're going to have the copy.
So let's select the heart GameObject in the hierarchy.
And let's drag it over to that prefabs folder.
In order to turn this heart into a prefab.
Now we as a sign it this heart.
Basically we just made a prefab, as you can see of this heart game object.