WEBVTT

00:00.080 --> 00:01.600
Let's create our coin.

00:01.640 --> 00:08.120
So I have the coin sprite in my UI folder, as you can see in project tab and then assets folder.

00:08.240 --> 00:09.840
So I'm going to select my this coin.

00:09.840 --> 00:11.600
So let's select this coin sprite.

00:11.640 --> 00:12.880
Let's go to Inspector.

00:12.880 --> 00:15.120
Click on this open Sprite editor.

00:15.280 --> 00:17.120
So we can see we have more than one.

00:17.120 --> 00:18.720
So we're going to slice individually.

00:18.720 --> 00:22.680
So we'll choose sprite mode to multiple filter mode to point no filter.

00:22.680 --> 00:24.360
And let's click on this apply.

00:24.680 --> 00:26.720
And let's slice it individually.

00:26.720 --> 00:30.160
Basically what we're going to do we're going to slice grid by cell count.

00:30.360 --> 00:32.000
So let's click on this slice.

00:32.000 --> 00:34.840
We're going to choose automatic to create by cell count.

00:34.880 --> 00:38.000
And let's count how many columns and rows we have.

00:38.440 --> 00:41.880
So 369 is nine columns.

00:41.880 --> 00:47.960
So I'm going to put nine columns not nine column exactly nine 1011.

00:47.960 --> 00:50.680
So we're going to put 11 columns and one row.

00:50.720 --> 00:52.920
After doing that let's click on this slice.

00:52.920 --> 00:55.560
And then let's click on this apply button.

00:55.560 --> 00:56.440
And now it's fine.

00:56.440 --> 00:59.160
So I'm going to select my game view once again here.

00:59.640 --> 01:03.360
And let's click on this arrow by now and I'm going to choose the first one.

01:03.360 --> 01:05.000
So let's select that.

01:05.000 --> 01:09.000
And we're going to drag it over to this in view or in this hierarchy.

01:09.240 --> 01:11.360
So as soon as we drag it we can see.

01:11.400 --> 01:14.640
But the problem is that is it is too much small.

01:14.640 --> 01:17.040
So we need to make it bigger in size.

01:17.040 --> 01:19.600
So I'm going to select our sprite sheet one more time.

01:19.600 --> 01:23.360
And let's make this sprite uh per unit something around 16.

01:23.360 --> 01:24.960
And let's click on this apply.

01:25.080 --> 01:29.480
And now we are able to see if you just want to make it a little bit bigger.

01:29.480 --> 01:33.880
Then you can just make this a pixel per unit even smaller number.

01:33.880 --> 01:38.320
So I'm going to choose something like uh 12 to make it a little bit bigger.

01:38.320 --> 01:39.800
Let's click on this apply.

01:40.000 --> 01:41.800
Now we can see it seems fine.

01:42.040 --> 01:46.720
So we're going to do the same thing as we created this heart uh heart game object.

01:46.720 --> 01:49.160
Basically we're going to have two animation.

01:49.280 --> 01:53.520
Uh, first will be this coin spinning which will spin around itself.

01:53.520 --> 01:56.560
And the second, uh, animation just going to be the collected one.

01:56.560 --> 01:59.950
Basically it will go up and over time it's going to fade out.

01:59.990 --> 02:04.510
Basically, we're going to do the same thing as we have done in this hard game object.

02:04.510 --> 02:09.630
So let's create an empty parent game object first because we're going to have to animation clip and

02:09.630 --> 02:10.510
the collected one.

02:10.510 --> 02:11.350
So that's why.

02:11.470 --> 02:12.670
So let's go to hierarchy.

02:12.670 --> 02:14.710
Let's right click or hit this plus icon.

02:14.710 --> 02:16.550
Let's create an empty game object.

02:16.550 --> 02:19.550
And I'm going to call this game object to something like coin.

02:19.950 --> 02:25.510
And and I'm going to select this uh tool move tool from this in view.

02:25.630 --> 02:32.790
And I'm going to choose an gizmos for that something this or this we can choose I'm going to choose

02:32.790 --> 02:33.470
this one.

02:33.790 --> 02:37.910
And I'm going to drag it top up in my hierarchy so I can see all the time.

02:37.910 --> 02:40.670
And now I'm going to select my this coin sprite.

02:40.830 --> 02:42.710
So let's select this coin sprite.

02:42.710 --> 02:48.710
And firstly I'm going to name it to something like coin sprite a coin sprite.

02:48.950 --> 02:55.590
And let's select this coin sprite in the hierarchy and drag it over to this coin game object in hierarchy.

02:55.750 --> 02:59.270
And we're going to go over to transform of this coin sprite.

02:59.310 --> 03:01.070
Let's right click there and reset.

03:01.070 --> 03:07.390
So it's going to reset the position as the position of our coin game object or the parent one as you

03:07.390 --> 03:08.110
can see.

03:08.110 --> 03:09.790
So let's add some component.

03:09.790 --> 03:14.110
So first thing we're going to add a rigid body 2D for a gravity.

03:14.110 --> 03:16.310
And we're going to set the gravity equal to zero.

03:16.310 --> 03:19.630
So it's not going to fall down due to our gravity.

03:19.630 --> 03:21.910
So let's select the coin parent one.

03:21.910 --> 03:24.190
So the select the parent one not the child.

03:24.390 --> 03:25.230
Select the parent.

03:25.230 --> 03:27.270
Go over to uh go over to Inspector.

03:27.270 --> 03:28.710
Click on Add Component.

03:28.710 --> 03:32.230
And we're going to add a rigid body 2D component.

03:32.510 --> 03:35.590
And let's set the gravity body type to kinematic.

03:35.590 --> 03:38.470
So it's not going to fall down due to gravity.

03:38.630 --> 03:44.150
And we're going to choose collision detection to continuous and interpolate to interpolate to just making

03:44.190 --> 03:44.870
out smooth.

03:44.910 --> 03:47.670
Or you can just leave it to none as well.

03:47.670 --> 03:49.230
This interpolate section.

03:49.230 --> 03:51.070
But I'm going to choose interpolate.

03:51.190 --> 03:57.620
And let's add one more component which will be the collider 2D for collision detection.

03:57.620 --> 04:03.300
So let's click on Add Component and I'm gonna add a box Collider 2D to just fit it perfectly.

04:03.300 --> 04:09.220
And let's click on this Edit Collider to edit the collider as the size of our coin sprite.

04:09.820 --> 04:12.780
And we can see this is fine by now.

04:13.060 --> 04:18.940
And make sure you just go to trigger and check this one underneath your box Collider 2D component.

04:18.940 --> 04:21.780
And now we are ready to create our animation.

04:21.780 --> 04:26.420
But before we create, let's assign this coin game object as a coin tag.

04:26.420 --> 04:27.540
So let's go to Inspector.

04:27.540 --> 04:29.700
Let's click on this untag add tag.

04:29.700 --> 04:33.500
And then we're going to click on this plus icon in order to add a tag.

04:33.700 --> 04:36.380
And we're going to create a coin tag something like that.

04:36.380 --> 04:37.380
And save it.

04:37.380 --> 04:43.340
And make sure you just go over to that GameObject once again and assign it the tag which you recently.

04:43.340 --> 04:44.500
So name it.

04:44.500 --> 04:48.020
So I assign it the coin game object as a coin tag.

04:48.060 --> 04:52.700
As you can see in Inspector, and we are ready to create our animation.

04:52.700 --> 04:56.740
To create the animation we're going to select the tile game object, not the parent.

04:56.740 --> 04:58.260
So we're going to select our child.

04:58.500 --> 05:03.060
And let's go to project tab sprites and then UI folder.

05:03.060 --> 05:06.500
Basically move over to that folder where you have the sprites.

05:06.500 --> 05:08.060
So I'm going to select all of these.

05:08.060 --> 05:09.620
So let's click on this arrow.

05:09.620 --> 05:13.740
And I'm going to select all of this coin sprite by holding down shift shift.

05:14.020 --> 05:16.380
Basically this coin individual sprites.

05:16.380 --> 05:22.420
And I'm going to drag it over to this coin sprite GameObject in the hierarchy in order to make the animation

05:22.420 --> 05:23.180
right away.

05:23.180 --> 05:25.900
And it's making our animation right away.

05:25.900 --> 05:31.700
Instead of instead of moving over to this animation tab and then click on that create button in order

05:31.700 --> 05:33.140
to create the animation.

05:33.140 --> 05:34.980
And this is pretty much first way.

05:34.980 --> 05:40.340
So you can just select all of the individual sprite, and then you can just drag it over to top of that

05:40.340 --> 05:44.900
game object in the hierarchy in order to make the animation even faster way.

05:44.900 --> 05:47.220
So I'm going to move over to my assets folder.

05:47.220 --> 05:52.500
In assets folder I have created this animation folder, so I'm going to open that up as well as I'm

05:52.500 --> 05:54.740
going to open up this stop animation.

05:54.740 --> 05:59.140
And I'm going to create a separate subfolder for my coin animation.

05:59.140 --> 06:01.540
So let's right click the new folder.

06:01.540 --> 06:05.540
And I'm going to name this folder to Coin Underscore Animation.

06:06.060 --> 06:10.540
And let's open up this subfolder as well by double clicking on it.

06:10.540 --> 06:12.380
And we have to name the animation.

06:12.380 --> 06:15.860
So this one is just going to be the spinning one coin coin spinning.

06:15.860 --> 06:20.460
So I'm going to call it coin underscore spinning spinning.

06:20.820 --> 06:21.700
And that's fine.

06:21.700 --> 06:23.500
And let's click on the save button.

06:23.660 --> 06:26.580
And it's it's going to create the animation right away.

06:26.580 --> 06:32.180
So now if we select our coin sprite in the hierarchy move over to animation tab and then click on this

06:32.180 --> 06:32.940
plus icon.

06:32.940 --> 06:36.700
We can see indeed the coin just spinning around itself.

06:36.700 --> 06:38.540
And this seems pretty much cool.

06:39.020 --> 06:42.620
And we're going to have another animation which will be the collected one.

06:42.620 --> 06:47.220
Basically this coin will go up and over time it's gonna fade out.

06:47.220 --> 06:48.980
So let's create that animation.

06:48.980 --> 06:51.700
So we're going to select our coin sprite in the hierarchy.

06:51.740 --> 06:53.140
Let's go to animation tab.

06:53.140 --> 06:56.450
Click over here and we're going to click on this Create New clip.

06:56.450 --> 07:00.130
And this is going to be the coin underscore uh the collected one.

07:00.130 --> 07:04.650
So I'm going to call it collected or collide one.

07:04.650 --> 07:09.210
So let's uh I'm going to call it collected instead collected.

07:09.210 --> 07:11.210
And let's click on the save button.

07:11.410 --> 07:13.370
And we need to make the animation.

07:13.370 --> 07:16.810
So let's click on this red button in order to record the animation.

07:16.810 --> 07:19.810
And I'm going to move over to 60 frames or one second.

07:20.010 --> 07:23.810
And I'm going to select my coin Sprite GameObject in the hierarchy.

07:23.810 --> 07:26.050
And let's move it up direction.

07:26.050 --> 07:30.090
And then over time we're gonna, uh, we're gonna make it fade out.

07:30.090 --> 07:35.930
So let's select the coin sprite, let's go to sprite Renderer component and a color.

07:35.930 --> 07:37.010
Let's click there.

07:37.010 --> 07:39.290
And in the bottom A which is 255.

07:39.290 --> 07:41.570
So I'm going to make it all the way to the zero.

07:41.690 --> 07:46.090
So once we make it zero we can see the coin just gets invisible.

07:46.090 --> 07:51.570
So we can just click on this play button in order to uh see the animation.

07:51.570 --> 07:55.370
So it's just going up and over time is just fading out.

07:55.410 --> 07:56.490
As you can see.

07:56.730 --> 08:01.010
And once you're done, you can just click on this red button to capture the animation.

08:01.010 --> 08:02.890
Or you can just leave it like that.

08:02.930 --> 08:05.490
It's automatically gonna capture the animation.

08:05.490 --> 08:11.010
So now if we select our coin sprite GameObject in the hierarchy, move over to animator tab.

08:11.010 --> 08:17.090
We can see we have animation where we have coin spinning as well as the coin collected.

08:17.090 --> 08:21.050
So we also need to make transition between these animation state.

08:21.050 --> 08:24.410
So let's right click on this coin animation spinning.

08:24.410 --> 08:26.810
And we're going to make transition to coin collect it.

08:26.810 --> 08:28.210
And let's select this transition.

08:28.210 --> 08:30.330
Go over to Inspector and we're going to untick.

08:30.330 --> 08:34.850
This has exit time as well as we're going to set the transition duration to zero.

08:34.850 --> 08:39.610
And we need to choose a condition in which condition we want to play the animation clip.

08:39.610 --> 08:42.690
So let's go to animator tab and let's select this parameter.

08:42.690 --> 08:44.250
Let's click on this plus icon.

08:44.250 --> 08:46.570
And we're going to choose a trigger in the bottom.

08:46.570 --> 08:52.250
And I'm going to call this trigger to something like collide as I have done in my hard game object.

08:52.280 --> 08:55.280
So basically we're just approaching the same way.

08:55.720 --> 08:57.520
And now I'm going to choose this color.

08:57.520 --> 09:00.960
So let's click on this plus icon in the condition Inspector.

09:01.280 --> 09:07.720
And now if we just click on this play button and manually just gonna manually try to trigger this collide

09:07.720 --> 09:08.440
parameter.

09:08.440 --> 09:10.600
You will see the coin collected animation.

09:10.600 --> 09:17.200
Just gonna play right away of this coin sprite as soon as we just trigger it manually.

09:17.200 --> 09:23.200
So if I just trigger, as you can see, as soon as we trigger it's just going up and over time it's

09:23.200 --> 09:23.960
just fading out.

09:23.960 --> 09:26.840
But the problem is that this animation is just looping.

09:26.840 --> 09:29.720
Basically it's just playing over again and again.

09:29.720 --> 09:31.320
So we want to stop that.

09:31.320 --> 09:35.320
So let's get out of play mode and we're going to move over to my project tab.

09:35.320 --> 09:40.680
Then assets then animation basically where we created or just place those animation clips.

09:40.680 --> 09:42.560
So we're going to move over to that folder.

09:42.560 --> 09:45.160
So I have this coin underscore animation.

09:45.160 --> 09:47.800
And we can see we have both of this animation clip.

09:47.800 --> 09:50.840
We have coin spinning as well as the coin collected.

09:50.840 --> 09:56.800
So I'm going to choose my coin collected and I'm going to uncheck this loop time in the in the inspector.

09:56.800 --> 09:59.280
So the animation clip will not loop.

09:59.840 --> 10:00.960
So now it's fine.

10:00.960 --> 10:06.240
And we need to make this coin a sprite coin GameObject in our hierarchy a prefab.

10:06.240 --> 10:07.560
So we're going to have the copy.

10:07.720 --> 10:10.480
So let's select the coin GameObject in the hierarchy.

10:10.480 --> 10:14.600
And let's drag it over to this prefabs folder in order to make it prefab.

10:14.640 --> 10:20.560
Now we just made it prefab as you can see, and we are ready to collect that one.

10:21.040 --> 10:27.640
Uh, so we just created and so we also need to uh, collect this coin, uh GameObject.

10:27.640 --> 10:28.680
So let's do that.

10:28.680 --> 10:31.400
So I'm going to select my player game object in the hierarchy.

10:31.520 --> 10:34.640
And let's open up the player script by double clicking on it.

10:35.160 --> 10:40.240
And what we're going to do we're going to use this same function one more time which is ontriggerenter.

10:40.240 --> 10:43.200
So this function get called when we trigger with something.

10:43.200 --> 10:48.040
And if we move to unity then our coin and then choose this coin sprite.

10:48.280 --> 10:51.760
Uh coin sprite coin game object, not the child one.

10:52.160 --> 10:54.360
Uh, and move over to Box Collider 2D.

10:54.400 --> 10:56.880
We can see we just check this box.

10:56.880 --> 11:04.040
So that's why we're going to use a ontriggerenter 2D function in order to, uh, check the trigger.

11:04.040 --> 11:07.640
And I'm going to move this coin sprite game object a little bit down.

11:07.640 --> 11:11.160
So this player game object easily can collect that one.

11:11.360 --> 11:14.440
So we assign it this coin game object as a coin tag.

11:14.440 --> 11:16.920
We can see in the inspector as well.

11:16.920 --> 11:18.080
So let's go to script.

11:18.080 --> 11:21.040
So this function get called when we trigger with something.

11:21.040 --> 11:24.760
And we can extract info by going over to this collision parameter.

11:24.760 --> 11:26.360
So I'm going to check it in the bottom.

11:26.360 --> 11:30.640
So I'm going to use this if condition and make first packet and some curly brackets.

11:30.640 --> 11:32.760
And what we want to check over here.

11:32.760 --> 11:35.360
We want to check whatever we triggered it with.

11:35.400 --> 11:37.840
If that game object has a tag called coin.

11:37.840 --> 11:42.960
So let's suppose if we trigger with this coin game object or collide with this coin game object, and

11:42.960 --> 11:47.600
we know we assigned this coin as a coin tag in the inspector, as you can see.

11:47.600 --> 11:49.910
So what we need to do in that situation?

11:49.910 --> 11:54.790
We need to collect this coin game object as well as we need to increase our coin.

11:54.790 --> 11:55.910
So let's go to Skip.

11:55.910 --> 11:59.230
And over here in this brackets we're going to check.

11:59.230 --> 12:01.590
So we're going to type collision dot game object.

12:01.590 --> 12:06.870
So basically we're just taking this parameter collision parameter in order to check and collision dot

12:06.870 --> 12:11.590
game object over here simply referencing the game object we triggered it with.

12:11.590 --> 12:15.030
So we definitely gonna trigger with that uh, coin game object.

12:15.030 --> 12:19.750
So collision dot game object over here is just going to be the coin game object.

12:19.750 --> 12:23.550
And then what we're going to do, we're going to extract the tag of the game object.

12:23.550 --> 12:25.590
So we're going to use this dot tag.

12:25.630 --> 12:27.950
And we're going to check if the tag is equals.

12:27.950 --> 12:34.390
Equals to coin means if we trigger with this coin game object and we do know we assign this coin as

12:34.390 --> 12:36.790
a coin tag means we just collecting that.

12:36.790 --> 12:41.510
So in that situation what we need to do and we're just doing it over here as you can see.

12:41.510 --> 12:47.110
So whatever we trigger it with if that game object has a tag called coin and we're checking it over

12:47.110 --> 12:48.790
here, as you can see.

12:48.790 --> 12:54.910
So if Collision's GameObject or tag if it's equals equals to coin means we just trigger it with that

12:54.910 --> 12:55.350
coin.

12:55.350 --> 12:59.510
So in that situation, what we need to do we need to increase our current coin.

12:59.510 --> 13:01.390
So let's go to top of our class.

13:01.390 --> 13:07.030
And let's create a variable to just keep track of how many coins we collected so far.

13:07.150 --> 13:11.270
And I'm going to do it somewhere in the bottom over here.

13:11.270 --> 13:15.390
And it doesn't need to be public so we can make it instead private.

13:15.390 --> 13:16.790
So I'm going to make it private.

13:16.830 --> 13:20.270
That will be int like whole number 01234.

13:20.430 --> 13:24.510
And I'm going to call this one to current coin current coin.

13:24.990 --> 13:27.510
And let's close that up with semicolon.

13:27.510 --> 13:30.430
So we just created this parameter which is current coin.

13:30.430 --> 13:34.150
In order to keep track of how many coins we collected so far.

13:34.390 --> 13:37.150
And I'm going to move over to this start function.

13:37.150 --> 13:39.710
So start function get call in the start of the game.

13:39.710 --> 13:42.310
So in the start of the game I have what I want to do.

13:42.350 --> 13:45.310
I'm going to set current coin equal to zero.

13:45.350 --> 13:46.590
Why we set it to zero.

13:46.590 --> 13:50.870
Because as soon as we're going to start our game, we're going to have zero coin.

13:50.910 --> 13:55.230
So that's why in the start of the game, I'm just setting current coin equal to zero.

13:55.270 --> 13:56.430
As you can see.

13:56.470 --> 13:58.950
And let's go to that line of code where we're triggering.

13:58.950 --> 14:00.550
So we're triggering over here.

14:00.550 --> 14:01.390
So what are we going to do.

14:01.390 --> 14:04.710
We're going to add current coin plus equal one.

14:04.750 --> 14:10.470
Or what you can simply do you can use this plus plus it also basically the same thing.

14:10.670 --> 14:13.750
So the current coin in the start of the game we have zero.

14:13.750 --> 14:17.550
And if we collide with that coin so what we're doing we just adding one.

14:17.550 --> 14:20.790
So this current coin is zero zero plus one.

14:20.790 --> 14:23.630
Or this plus plus basically means we're just adding one.

14:23.630 --> 14:26.110
So zero plus one is just going to be one.

14:26.110 --> 14:29.590
And if we collect the second coin so the current coin is now one.

14:29.590 --> 14:35.830
So one plus one is going to be two means we will increase our current coin once we trigger with that

14:35.830 --> 14:37.070
coin game object.

14:37.230 --> 14:42.390
And what we also need to do, we need to play the animation clip of that coin collected.

14:42.390 --> 14:47.980
So let's suppose we just collide with this coin game object means instead of playing the spinning of

14:47.980 --> 14:52.180
this coin right now, we need to play the collected, collected.

14:52.180 --> 14:56.540
And we can see we have in this coin sprite the animator component.

14:56.540 --> 15:02.620
So once we created this animation clip, this coin spinning, as well as the coin collected and animator

15:02.620 --> 15:04.980
component just added to this coin sprite.

15:04.980 --> 15:08.980
So basically what we have to do, we need to move over to parent GameObject first.

15:08.980 --> 15:14.740
So in our case coin and by that we can access this coin sprite child game object.

15:14.740 --> 15:17.500
And then we're going to move over to this animator component.

15:17.500 --> 15:20.060
And then we're going to trigger this collide parameter.

15:20.060 --> 15:25.900
And we do know once we're gonna trigger it's going to play the coin collected animation clip right away.

15:25.900 --> 15:32.100
So basically that is the thing we have done the same thing or we just doing in a same way as we have

15:32.100 --> 15:35.140
done already in our hard game object.

15:35.140 --> 15:36.260
So let's do that.

15:36.260 --> 15:41.380
So after increasing our current coin we're gonna play the collected animation clip.

15:41.380 --> 15:46.140
So we're gonna use this collision game object and collision game object over here.

15:46.180 --> 15:48.020
This is gonna be the coin game object.

15:48.020 --> 15:51.380
And then we're gonna move over to Coin game Object Transform component.

15:51.380 --> 15:53.820
And then we're going to use this dot get cell.

15:53.860 --> 15:55.260
And we're going to get the child.

15:55.300 --> 15:58.860
So the we're looking for is a file child or the coin sprite.

15:58.860 --> 16:03.260
So that's why we're going to put zero zero basically means the referencing the first child.

16:03.260 --> 16:06.540
And we have only one child in that coin game object.

16:06.540 --> 16:10.260
So the get child over here zero is gonna be the coin sprite.

16:10.260 --> 16:13.420
So basically we're just going over to that coin sprite game object.

16:13.420 --> 16:15.580
And now we're going to get the animator component.

16:15.580 --> 16:17.860
So we're going to use this Getcomponent function.

16:18.140 --> 16:22.500
Sorry Getcomponent as syntax or this get component.

16:22.940 --> 16:28.580
And in this arrows we need to pass the component name that we really looking for.

16:28.580 --> 16:32.620
So in our case we just need to get the animator component.

16:32.620 --> 16:38.100
So in arrows we're going to pass this animator component and then make first bracket and then dot.

16:38.100 --> 16:43.060
We're going to use this set trigger function in order to trigger that parameter and make first bracket.

16:43.060 --> 16:44.930
Then close that off with Semicolon.

16:44.930 --> 16:49.650
So in this bracket you need to pass the parameter name in quotation.

16:49.650 --> 16:52.370
And the parameter name we're going to pass it called light.

16:52.370 --> 16:57.370
We can see in the inspector sorry we can see in our animator tab which is collide.

16:57.370 --> 17:01.450
So basically what we're doing we're just going over to this coin game object.

17:01.450 --> 17:05.890
And then we're just moving over to this transform component of this coin game object.

17:05.890 --> 17:11.730
And by this transform component which is moving over to this coin sprite game object, as you can see

17:11.730 --> 17:13.810
over here, a coin sprite.

17:13.810 --> 17:17.250
And then after that we're just going over to animator component.

17:17.250 --> 17:23.050
So when we uh moved moved over to this coin sprite, then we're just taking this animator component

17:23.050 --> 17:25.890
as you can see, which is Getcomponent animator.

17:25.890 --> 17:31.010
And then we just, uh, using this trigger function in order to trigger the parameter.

17:31.010 --> 17:33.730
So basically we're just triggering this collide parameter.

17:33.730 --> 17:39.050
And we do know once we trigger this parameter it's going to play the coin collected animation clip right

17:39.050 --> 17:39.450
away.

17:39.650 --> 17:44.690
Uh so we're just triggering the collide parameter as you can see in our code.

17:44.730 --> 17:47.970
Now we're going to press down Ctrl S in order to save our script.

17:47.970 --> 17:49.890
And now let's move over to unity.

17:51.810 --> 17:57.570
So basically we're just moving over to this coin sprite game object and then moving over to this animator

17:57.570 --> 17:58.210
component.

17:58.210 --> 18:04.210
And by this animator component of this coin sprite, we're just getting this collide parameter add.

18:04.250 --> 18:09.650
And we do know once we trigger it's going to play the coin collected animation clip right away.

18:09.650 --> 18:11.250
So let's have a look on this.

18:11.810 --> 18:14.530
And I'm going to click on this play button in the top.

18:14.650 --> 18:21.370
And if I select my player game object uh we can not able to see our current coin because we just made

18:21.370 --> 18:22.290
it private.

18:22.410 --> 18:25.610
Uh, that current coin parameter as a private field.

18:25.610 --> 18:28.770
So let's suppose you still want to see that private field.

18:28.770 --> 18:34.210
So what you need to do in that situation go over to inspector in the top right Inspector you can see

18:34.250 --> 18:34.730
three dots.

18:34.730 --> 18:37.970
So just click there and then click click on this debug.

18:38.010 --> 18:44.090
And as soon as we have chosen debug we can see underneath our player skip in the bottom current coin

18:44.090 --> 18:45.530
and it's set to zero.

18:45.530 --> 18:47.930
So let's click on this play button in the top.

18:48.090 --> 18:54.450
And once we collect this coin game object you will see this current coin just going to increase by one.

18:54.450 --> 18:56.210
So let's have a look on this.

18:56.210 --> 19:01.530
So just take a moment to give it give it a moment to just play that.

19:02.050 --> 19:04.170
So I'm gonna trigger with this coin.

19:04.850 --> 19:07.410
And as soon as we trigger it or collide it.

19:07.410 --> 19:10.770
So I'm going to click on this pause button in the top to pause my game.

19:10.770 --> 19:15.090
And if we move over to player skip we can see current coin is now one.

19:15.090 --> 19:19.770
And as soon as we trigger it, it just plays the coin collected animation clip.

19:19.770 --> 19:24.530
And basically it's just going up and over time it's just fading out.

19:24.850 --> 19:28.010
Uh, so that basically it's just playing perfectly.

19:28.010 --> 19:33.970
But the problem is that if we move over to a hierarchy, we can see the coin game object still laying

19:34.010 --> 19:38.010
around in the hierarchy as well as in the scene view we can see.

19:38.010 --> 19:41.330
So after one second, what we need to do, we need to destroy this.

19:41.400 --> 19:41.800
Why?

19:41.840 --> 19:45.880
Because after one second, we're just completing the whole animation clip.

19:45.880 --> 19:52.080
So after one second, we also need to destroy this coin GameObject, because we collected that one and

19:52.080 --> 19:55.240
we increased our current coin by one unit.

19:55.240 --> 20:00.280
So let's get out of play mode and I'm gonna move over to my inspector mode one more time.

20:00.280 --> 20:02.560
So just go over to top right three dot.

20:02.600 --> 20:08.160
So just click there and then click on this normal in order to go back in normal mode.

20:08.160 --> 20:14.920
So if we select our coin sprite in the hierarchy move over to animation tab and then choose this coin

20:14.920 --> 20:15.560
collected.

20:15.600 --> 20:22.600
We can see after one second the collected animation clip is playing are playing perfectly.

20:22.600 --> 20:22.920
So.

20:22.920 --> 20:28.200
So after one second it's just a fading or it's get totally invisible.

20:28.200 --> 20:33.120
So after this amount of time, we also need to delete the coin game object or the child.

20:33.120 --> 20:39.840
So if we select if we delete or destroy this coin GameObject, other child will also be destroyed with

20:39.880 --> 20:44.520
it because the coin sprite is the child of our coin game object, so that's why.

20:44.560 --> 20:45.760
So let's go to school.

20:45.960 --> 20:47.120
So let's go to script.

20:47.120 --> 20:51.080
So after triggering that parameter we're going to use this destroy function.

20:51.080 --> 20:53.760
And we do not destroy function as a first argument.

20:53.760 --> 20:56.360
It's going to take the game object you want to destroy.

20:56.360 --> 20:59.600
So in our case we're going to pass this collision game object.

20:59.600 --> 21:03.160
It basically means the game the game object we triggered it with.

21:03.160 --> 21:06.040
So we definitely gonna trigger with that coin game object.

21:06.040 --> 21:09.760
So collision game object means over here the coin game object.

21:09.760 --> 21:12.640
And the second thing we're going to specify the time.

21:12.640 --> 21:13.920
So we're going to put one f.

21:13.920 --> 21:18.680
And we do know after one f or once again it's just completing the whole animation clip.

21:18.680 --> 21:22.880
So that's why as a second parameter we just specified our time.

21:22.880 --> 21:24.760
And we're going to close that off with semicolon.

21:24.760 --> 21:27.880
And let's save our script and let's move to unity.

21:27.880 --> 21:34.240
So after one second you will see this coin game object will also be destroyed from the hierarchy as

21:34.240 --> 21:35.640
well as the scene view.

21:35.640 --> 21:41.510
Because we destroying after one second as a second parameter we just specified our time.

21:41.750 --> 21:45.750
So let's click on this play button in the top and have a look on this.

21:51.310 --> 21:53.070
So just wait for to compile.

21:54.990 --> 21:57.710
And let's try to collect this coin game object.

21:57.710 --> 21:59.110
And you will see that.

22:00.190 --> 22:02.790
So as you can see it's played collected.

22:02.790 --> 22:09.990
And if I just pause my game and move over to hierarchy, we cannot see able to see the coin game object

22:09.990 --> 22:14.110
at all in this hierarchy as well as in the scene view.

22:14.150 --> 22:20.150
As you can see, means after once again playing the whole animation clip, which is the collected one,

22:20.190 --> 22:23.150
it just gets destroyed after playing that.

22:23.350 --> 22:24.630
So I hope you get the idea.

22:24.630 --> 22:26.270
So I'm gonna get out of play mode.

22:26.270 --> 22:28.030
And basically that is the thing.

22:28.030 --> 22:33.590
So make sure you just make your coin game object as well a prefab so you can have because we're gonna

22:33.590 --> 22:36.030
place this coin in our ground tiles.

22:36.350 --> 22:39.750
We're gonna have multiple coins in order to collect them.
