WEBVTT

00:00.040 --> 00:00.880
We need to show up.

00:00.920 --> 00:03.160
How many coins we collected so far?

00:03.240 --> 00:05.520
So we're going to create a coin UI.

00:05.560 --> 00:08.960
So we're going to move over to our canvas in the hierarchy.

00:09.480 --> 00:10.680
So let's select the canvas.

00:10.680 --> 00:13.920
And we're going to press down F in order to focus on that.

00:14.040 --> 00:16.760
So to create an icon first.

00:16.760 --> 00:17.680
So let's do that.

00:17.680 --> 00:20.960
So we're going to move over to this canvas and then UI GameObject.

00:21.080 --> 00:23.440
Let's right click on this UI GameObject.

00:23.440 --> 00:24.560
Let's go to UI.

00:24.560 --> 00:27.000
And then we're going to choose this icon image.

00:27.240 --> 00:30.440
And we're going to call this one to something like coin Sprite.

00:30.600 --> 00:37.480
So let's call it coin Sprite and make sure you just go to Image Component and then Inspector.

00:37.480 --> 00:39.680
And we need to replace this source image.

00:39.680 --> 00:41.360
And it says sprite.

00:41.360 --> 00:44.080
So we're going to replace with our coin sprite.

00:44.080 --> 00:46.560
So let's move to project tab then assets.

00:46.560 --> 00:49.880
And then I'm going to move over to my this UI folder.

00:49.880 --> 00:52.120
And I can see I have the coin sprite.

00:52.120 --> 00:53.640
So I'm going to select my first one.

00:53.640 --> 00:57.160
So let's select that and drag it over to this source image field.

00:57.200 --> 01:01.090
As soon as we drag it now we can see our coin sprite.

01:01.450 --> 01:02.330
Uh, coin sprite.

01:02.330 --> 01:06.330
And instead of saying coin sprite we're going to say something like icon.

01:06.330 --> 01:09.930
So let's call it coin coin icon.

01:09.930 --> 01:12.250
So basically this is going to be the icon.

01:12.250 --> 01:16.010
So that's why and we're going to move it uh to top left corner.

01:16.170 --> 01:20.010
So let's select the coin icon and let's go to Inspector Rect Transform.

01:20.010 --> 01:21.130
Click over here.

01:21.130 --> 01:24.530
And then we're going to hold down alt and select this top left one.

01:24.570 --> 01:26.090
As soon as we have chosen.

01:26.090 --> 01:28.530
Now it's gets over to top left.

01:28.530 --> 01:31.210
And I'm going to move it somewhere over here.

01:32.050 --> 01:35.690
And this seems pretty much fine by now as you can see.

01:36.170 --> 01:42.730
And we need to create a text over here in order to reference how many coins we collected so far.

01:42.730 --> 01:45.970
So it's we also need to show that up in UI.

01:46.170 --> 01:48.890
So I'm going to select my this text right over here.

01:48.930 --> 01:51.210
As you can see this text.

01:51.210 --> 01:55.290
And I'm going to press down control D in order to duplicate that.

01:55.290 --> 01:56.890
So I'm going to press down Ctrl D.

01:57.130 --> 01:58.630
And after duplicating.

01:58.630 --> 02:00.630
So let's select the right tool from here.

02:00.630 --> 02:07.870
And I'm going to move it down somewhere over here I guess uh this seems pretty much fine by now.

02:07.870 --> 02:14.590
And you can notice over here and instead of saying text, I'm going to say something like, uh, coin

02:14.630 --> 02:15.990
current coin text.

02:15.990 --> 02:22.750
So let's call it current uh, current coin text or txt for text.

02:23.030 --> 02:25.190
And this is pretty much fine by now.

02:25.510 --> 02:28.030
And we're going to move over to the parent game object.

02:28.030 --> 02:30.790
So in our case UI let's go to overrides.

02:30.790 --> 02:33.390
And then we're going to click on this apply all.

02:33.630 --> 02:39.190
So the changes we made it's going to be saved into this UI GameObject prefab as well.

02:39.190 --> 02:45.390
So if we move over to current coin text then text component in Inspector we can change the value over

02:45.390 --> 02:45.630
here.

02:45.630 --> 02:47.310
Something like we can set it to one.

02:47.310 --> 02:48.350
We can set it to three.

02:48.390 --> 02:51.430
We can set it to uh four as well.

02:51.870 --> 02:57.920
So what we basically need we need a reference of this text component of this current coin text, then

02:57.920 --> 03:03.720
we can just link up this text with our current coin or how many coins we collected so far.

03:03.880 --> 03:06.000
So by default, I'm gonna set it to zero.

03:06.000 --> 03:08.560
And let's open up the script where we're collecting.

03:08.680 --> 03:12.440
So I'm gonna open up I'm going to select my player GameObject in the hierarchy.

03:12.440 --> 03:15.120
And let's open up the player script where we're collecting.

03:15.120 --> 03:20.960
So if we just scroll down and I use this coin over here, as you can see.

03:20.960 --> 03:24.320
So we increasing our current coin by one.

03:24.360 --> 03:28.560
As you can see then playing our coin collected animation clip.

03:28.560 --> 03:31.800
And after that we just destroying our coin right away.

03:31.960 --> 03:34.560
So we also need to show this up in UI.

03:34.720 --> 03:39.200
So let's go to the top of our class and let's create a text component.

03:39.200 --> 03:43.160
So basically what we need we need a reference of this current coin text.

03:43.160 --> 03:45.200
Basically this text component.

03:45.200 --> 03:46.920
And the inspector we can see.

03:46.920 --> 03:48.760
So we need a reference of this.

03:48.760 --> 03:51.840
Then we can link up with our current coin text.

03:51.840 --> 03:53.160
So let's go to script.

03:53.160 --> 03:55.820
And I'm gonna move over to top of over here.

03:55.820 --> 03:57.820
So let's make a serialized film.

03:58.140 --> 04:02.820
So we're going to make a serialized film, and that will be private.

04:03.020 --> 04:04.540
And we're going to make it.

04:04.580 --> 04:07.420
That component we're looking for is a text type.

04:07.420 --> 04:12.700
So make sure you before you type the component name, just go to the top of your class and include this

04:12.700 --> 04:16.220
namespace and call using Unityengine dot UI.

04:16.260 --> 04:23.220
It's going to allow us in order to use the UI elements, because we do know this text component is a

04:23.260 --> 04:24.340
UI element.

04:24.340 --> 04:30.500
So that's why we need to include this namespace in top of our class, which is using Unityengine dot

04:30.660 --> 04:31.300
UI.

04:31.460 --> 04:37.020
So now we're going to grab the reference and we have to name the component or the reference what we

04:37.020 --> 04:37.820
want to name it.

04:37.820 --> 04:42.540
So I'm going to call it something like current context as I name it in Inspector.

04:42.540 --> 04:44.620
So I'm going to call it current context.

04:44.620 --> 04:47.340
And let's press down Ctrl S to save our script.

04:47.340 --> 04:48.740
And let's move to unity.

04:48.740 --> 04:55.950
So underneath our player we're going to able to see another text component just gonna appear and we

04:55.950 --> 04:57.590
just name it current coin text.

04:57.590 --> 05:04.510
So what we basically have to do there, we need to drag this text component into that field.

05:04.510 --> 05:05.870
So just wait for it to compile.

05:05.870 --> 05:08.350
And once it's done we are ready to do that.

05:08.350 --> 05:09.870
So just wait for to compile.

05:10.110 --> 05:17.070
And now if I move to hierarchy uh, then uh player uh game object underneath our player skip, we can

05:17.070 --> 05:20.910
see current coin text and it says none text basically empty.

05:20.910 --> 05:25.950
So what we're gonna do, we're gonna select this current coin text object and let's drag it there.

05:25.950 --> 05:29.510
And we do know inside this current coin text we have the text component.

05:29.510 --> 05:33.270
So that's why we need to drag this game object into that slot.

05:33.270 --> 05:35.990
And now we can see we have the current coin text.

05:36.030 --> 05:38.870
As you can see underneath our player skip.

05:38.870 --> 05:42.590
Basically we have this reference now of this text component.

05:42.590 --> 05:47.230
And now we are ready to set our link up with our current coin.

05:47.270 --> 05:49.390
How many coins we collected so far.

05:49.510 --> 05:51.390
So let's go to our script.

05:51.390 --> 05:52.630
And over here.

05:54.250 --> 05:54.810
over here.

05:54.810 --> 05:55.730
We're doing it.

05:56.050 --> 05:57.130
So let's go to heart.

05:57.130 --> 06:02.490
So as you can see, we what we're doing basically we're just increasing our max health by one.

06:02.490 --> 06:06.370
So after increasing sorry not Max I'm really apologize.

06:06.410 --> 06:10.570
Basically increasing our current coin by one as you can see.

06:10.610 --> 06:14.570
And after that what we need to do we need to update the text as well.

06:14.570 --> 06:18.690
So what we will do, we will uh, move over to current coin text.

06:18.690 --> 06:24.370
And then I'm gonna access the text and we will set equal to current coin how many we collected.

06:24.410 --> 06:26.370
And let's close that up with semicolon.

06:26.370 --> 06:29.770
So as you can see this current coin is a integer value.

06:29.770 --> 06:36.650
If you if we move over to top of our class we can see over here we just created that parameter current

06:36.650 --> 06:37.010
coin.

06:37.010 --> 06:39.090
And that is a int parameter.

06:39.090 --> 06:42.970
And this text right over here is a string parameter.

06:43.050 --> 06:44.010
And this is string.

06:44.010 --> 06:46.010
And this is a integer value.

06:46.010 --> 06:52.100
So what we basically have to do we need to convert this integer this one which is current coin into

06:52.100 --> 06:53.220
a string value.

06:53.220 --> 06:58.500
So in order to convert that, we need to use these two string dot two string and make the make this

06:58.500 --> 06:59.380
first bracket.

06:59.380 --> 07:01.380
And now we're going to close that up with semicolon.

07:01.380 --> 07:03.180
And let's move over to unity.

07:03.180 --> 07:04.900
So what we basically doing.

07:04.900 --> 07:07.740
We're just going over to current context dot x.

07:07.740 --> 07:10.060
And we're setting equal to current coin.

07:10.380 --> 07:12.900
So let's suppose current coin we collected one.

07:12.900 --> 07:16.500
So as we collide with the first coin we're going to collect that.

07:16.500 --> 07:19.100
So current coin is going to be one if we collect.

07:19.100 --> 07:21.980
So the current coin over here just going to be one.

07:21.980 --> 07:25.180
So that's why this current coin takes dot x right over here.

07:25.180 --> 07:30.660
It's just going to be one because we directly sending it as you can see simply we're just moving over

07:30.660 --> 07:35.100
to this current coin and then accessing this accessing this text.

07:35.100 --> 07:36.900
As you can see in the inspector.

07:36.900 --> 07:40.060
And we're setting this text equal to our current coin.

07:40.060 --> 07:43.740
And let's suppose current coin right over here as one.

07:43.740 --> 07:48.900
So this current coin text dot text is just going to be one right away because we directly setting it.

07:48.900 --> 07:50.800
So this text takes right over here.

07:50.800 --> 07:56.440
This is going to be, uh, just going to be one according to how many coins current coin we collected

07:56.440 --> 07:57.000
so far.

07:57.040 --> 07:59.040
Other coins we collected so far.

07:59.160 --> 08:01.200
So so let's have a look on this.

08:01.200 --> 08:03.400
So I'm going to click on this play button in the top.

08:03.400 --> 08:07.960
And you will see as soon as we're going to collect that coin this is spinning coin.

08:07.960 --> 08:15.480
You will see the text will also be will change because after collecting that we also just uh updating

08:15.480 --> 08:16.840
in the text as well.

08:16.840 --> 08:19.880
So just wait for, to collect this, uh, current coin.

08:20.360 --> 08:25.200
And as soon as we collect it, as you can see current coin we have now one.

08:25.200 --> 08:30.760
So if I just click on this pause button in the top in order to pause my game and move over to my player

08:30.800 --> 08:35.840
GameObject in the hierarchy, then player skip, we not able to see the current coin because we need

08:35.840 --> 08:37.640
to move over to debug mode.

08:37.640 --> 08:39.760
So I'm going to move over to top right three dots.

08:39.760 --> 08:42.520
So let's click there and let's click on this debug.

08:42.680 --> 08:48.000
And as soon as we have chosen debug we can see current coin is now one in the bottom.

08:48.000 --> 08:50.170
So that's is why this takes right over here.

08:50.210 --> 08:53.210
It also changes with the current coin which is one.

08:53.210 --> 08:57.810
So the text right over here just uh, gets one as well.

08:58.090 --> 09:04.050
And uh, as well, basically if we move over to UI GameObject underneath our canvas, then current coin

09:04.090 --> 09:11.570
text, we can see, uh, if we scroll down, we can see the text over here becomes as one.

09:11.570 --> 09:13.130
So basically that is the thing.

09:13.170 --> 09:14.730
So I'm going to get out of play mode.

09:14.930 --> 09:17.330
And I'm going to move over to normal mode.

09:17.330 --> 09:23.570
And in order to go normal mode, make sure you just go one more time to the top right and click on this

09:23.570 --> 09:24.130
three dots.

09:24.130 --> 09:28.330
And then click on this normal mode in order to go back in normal mode.

09:28.330 --> 09:29.930
So basically that is the thing.

09:29.970 --> 09:32.730
And we're going to select our player GameObject in the hierarchy.

09:32.730 --> 09:35.850
Let's go to overrides and we're going to click on Apply All.

09:35.850 --> 09:42.290
So the changes we made over here it's going to be saved into this player GameObject prefab as well.

09:42.290 --> 09:43.970
So basically that is the thing.

09:43.970 --> 09:51.430
So I hope you get the idea that how you can just use the text in order to in order to link up with something

09:51.430 --> 09:54.550
that you really want to link with.

09:54.630 --> 09:56.870
So it's totally up to you basically.

09:57.310 --> 10:03.790
And if you just have don't want to duplicate, then you can just go over to this UI game object or simply

10:03.790 --> 10:05.190
this canvas as well.

10:05.270 --> 10:10.750
So we created the UI, a game object, in order to keep all of the things in an organized way.

10:10.910 --> 10:13.870
And we just made it the size as our canvas.

10:13.870 --> 10:18.430
So you can just simply right click on this UI game object and then move over to UI.

10:18.550 --> 10:21.670
And in the bottom you can see legacy and then choose this text.

10:21.670 --> 10:27.030
If you just want to current want to create the current context instead of duplicating.

10:27.070 --> 10:33.070
Or you can simply select this text underneath your UI game object underneath canvas, and then you can

10:33.070 --> 10:36.470
just press down control D in order to duplicate that.

10:36.470 --> 10:39.350
And you can just rename that to something else.

10:39.630 --> 10:45.830
I hope you get the idea that how you can do this, and I'm going to move over to UI overrides and then

10:45.830 --> 10:46.670
apply all.
