WEBVTT

00:00.040 --> 00:04.080
We will create a script in order to keep track of how much this is.

00:04.200 --> 00:06.840
A player game object made our score.

00:06.840 --> 00:09.040
So how much score we made so far?

00:09.160 --> 00:11.080
So we're gonna keep track of that.

00:11.080 --> 00:12.920
So we're going to create a script for it.

00:12.920 --> 00:17.040
So let's move over to this project tab, then assets and then script folder.

00:17.040 --> 00:20.800
So let's right click there create and then Monobehaviour script.

00:20.840 --> 00:24.160
And you can name that script to something like Score Manager.

00:24.160 --> 00:27.400
I already have created a script called Score Manager.

00:27.400 --> 00:29.480
And over here you can see that.

00:29.480 --> 00:34.920
So what we need to do now, we need to attach this script to any game object of our hierarchy.

00:34.920 --> 00:38.480
Or we can simply create a separate GameObject for this script.

00:38.480 --> 00:41.680
But I'm going to attach this script to my player game object.

00:41.680 --> 00:47.120
So I will select my player game object in the hierarchy, and let's select script and drag it over to

00:47.160 --> 00:50.160
this Add Component section in the Inspector.

00:50.160 --> 00:54.240
And we're going to double click this in order to open it up in Visual Studio.

00:54.240 --> 00:56.480
And we will go to the top of our class.

00:56.640 --> 01:02.860
And what we're going to do, we're going to make a serialized film, serialized film that will be private.

01:02.860 --> 01:08.900
So even we set it to private, we will still gonna be able to see this parameter underneath our score

01:08.900 --> 01:09.700
manager script.

01:09.740 --> 01:09.980
Why?

01:10.020 --> 01:12.460
Because we just marked as a serialized field.

01:12.500 --> 01:13.660
As you can see.

01:13.700 --> 01:14.860
And that will be float.

01:14.860 --> 01:18.500
And we can simply call this one to something like current score.

01:18.620 --> 01:24.300
So let's call it current score, current score, current score.

01:24.500 --> 01:26.340
And let's close that up with semicolon.

01:26.460 --> 01:30.020
And what I'm going to do I'm going to move over to this start function.

01:30.020 --> 01:32.980
So this start function get call in this start of the game.

01:32.980 --> 01:36.780
So in this start of the game I just want to set the current score to zero.

01:36.940 --> 01:40.220
So I will set current score equal to zero f.

01:40.340 --> 01:42.540
And let's close that up with semicolon.

01:42.540 --> 01:43.980
So why we set it to zero.

01:43.980 --> 01:47.180
Because in the start of the game we're gonna have zero score.

01:47.180 --> 01:52.140
So that's why in the start function I just set a current score equal to zero.

01:52.140 --> 01:55.420
And now what we're going to do we're going to move over to this update function.

01:55.420 --> 01:58.630
So we do know that update function runs every single frame.

01:58.630 --> 02:03.510
So every single frame, what I want to do, I just want to keep increasing this current score.

02:03.510 --> 02:08.870
So top of this current score, I'm going to add some a number in order to increase that.

02:08.870 --> 02:16.100
So we will do current score and top of that plus equal we're going to multiply something like 0.1 or

02:16.100 --> 02:17.110
0.1 f.

02:17.150 --> 02:22.190
So I'm going to multiply with 0.1 f or basically simply a lower number.

02:22.190 --> 02:26.230
And make sure you just multiply this number with time.deltatime.

02:26.230 --> 02:31.990
So over in frame rate this number just going to be constant means every single time this number will

02:31.990 --> 02:32.990
be constant.

02:32.990 --> 02:39.430
And if we just don't multiply this number with time.deltatime then this number will gradually increase.

02:39.430 --> 02:45.150
So to just make it a constant we just multiply it with time delta time as you can see.

02:45.150 --> 02:47.950
So the current score in the start of the game is zero.

02:47.950 --> 02:48.750
So zero.

02:48.750 --> 02:53.710
And top of that we just adding every single frame a we're doing inside this update function.

02:53.710 --> 02:57.050
And we do know that update function runs every single frame.

02:57.050 --> 03:01.490
So every single frame we just add on top of this current score some small number.

03:01.530 --> 03:02.570
As you can see.

03:02.610 --> 03:09.370
And also make sure you just multiply with time times delta time to in order to make that number constant.

03:09.450 --> 03:12.050
Now we're going to press down Ctrl S to save our skin.

03:12.050 --> 03:13.730
And let's move over to unity.

03:13.930 --> 03:21.130
So as soon as we're gonna start our game, uh, you will see the current current score just gonna increase,

03:21.290 --> 03:23.090
uh, over again and again.

03:23.090 --> 03:28.530
So just wait for to compile, and we can see underneath our score manager script.

03:28.530 --> 03:30.530
Current score by default is zero.

03:30.690 --> 03:37.050
And if we just click on this play button in the top, you will see as the time progress this current

03:37.050 --> 03:43.370
score just gonna keep increasing over and over because we're just doing inside that update function.

03:43.810 --> 03:49.610
And as you can see as soon as the game started we can see our current score just increasing.

03:49.610 --> 03:54.730
But the problem is that we can see this is too much even it's not touching at 0.1.

03:55.010 --> 03:55.910
Sorry one.

03:56.110 --> 03:57.390
And now it starts.

03:57.430 --> 03:57.670
One.

03:57.670 --> 04:01.910
So what we will do, we will get out of play mode and we will move over to script.

04:01.910 --> 04:07.470
So we're going to increase this number instead of passing point one we're going to pass something around

04:07.470 --> 04:14.350
ten to just increase uh, a uh to just increase our current score a little bit fast.

04:14.350 --> 04:20.710
So what you can simply do, you can make a variable for this as well by going over to this, uh, serialized

04:20.710 --> 04:20.950
field.

04:20.950 --> 04:22.070
So let's make that.

04:22.070 --> 04:24.430
So we're going to make a another serialized field.

04:24.430 --> 04:27.270
So make sure you just make this square brackets first.

04:27.270 --> 04:29.270
So I'm going to make square brackets sorry.

04:29.590 --> 04:31.590
And we're going to pass serialized field.

04:31.710 --> 04:33.430
And we're going to call this one.

04:33.430 --> 04:35.630
So this will be private float.

04:35.630 --> 04:37.390
And we will call amount.

04:37.390 --> 04:39.670
So let's call it amount something like that.

04:39.670 --> 04:41.990
And by default I'm going to give a default value.

04:41.990 --> 04:44.590
So set I'm going to set equal to ten.

04:45.150 --> 04:49.110
And now I'm going to replace this ten f with our amount.

04:49.110 --> 04:52.270
And we can adjust it underneath our score manager script.

04:52.270 --> 04:54.930
So that's why we just marked as a serialized field.

04:54.930 --> 04:57.810
So it's just going to make a private field a public.

04:57.810 --> 05:04.010
So we will see this parameter underneath our score manager script, which will be ten by default.

05:04.010 --> 05:07.690
We set but we can adjust underneath our inspector.

05:08.090 --> 05:10.610
So that's why we just marked as a serialized field.

05:10.610 --> 05:15.610
So we don't need to come to this script and change this number all over again and again.

05:15.610 --> 05:19.770
So that's why we just created a created a variable for this.

05:19.770 --> 05:22.570
And now we're going to press down Ctrl S to save our script.

05:22.570 --> 05:24.730
And let's move to unity by now.

05:24.730 --> 05:25.770
And let's have a look.

05:25.770 --> 05:28.610
So underneath our current score we will see.

05:28.650 --> 05:31.770
We will see another field just going to appear amount.

05:31.770 --> 05:33.570
And by default we set ten unit.

05:33.570 --> 05:37.730
But you can just give it any number that you like I'm gonna live with ten.

05:37.930 --> 05:40.810
And let's click on this play button in the top by now.

05:40.810 --> 05:42.730
And let's have a look on this.

05:42.730 --> 05:47.770
So the current score by now it's just going to keep increasing a little bit fast.

05:47.810 --> 05:48.930
The current score.

05:48.970 --> 05:51.690
Let's have a look on this because the amount is big.

05:51.730 --> 05:55.340
And we can see the current score is now increasing too much fast.

05:55.700 --> 06:01.980
It's already touched over 50 cross over 50, 70 and 80 and the list just goes on.

06:02.140 --> 06:04.580
But the problem is that if we just die.

06:04.620 --> 06:07.900
So let's take damage from this enemy game object.

06:07.900 --> 06:14.740
And indeed we just taking damages from this and we can see our player game objects now get destroyed.

06:16.260 --> 06:19.100
But the problem is that we have done a mistake.

06:19.700 --> 06:26.340
Basically, if we select our player game object in the hierarchy and we do know that we just attach

06:26.340 --> 06:29.140
this score manager script to this player game object.

06:29.140 --> 06:34.940
So once we destroy our player game object, this score manager is also destroying with it.

06:34.980 --> 06:35.260
Why?

06:35.300 --> 06:39.820
Because this score manager script is a component of this player game object.

06:39.820 --> 06:46.420
So instead of attaching this score manager game object to this player score manager sorry score manager

06:46.420 --> 06:50.260
script to the player, we need to attach A in somewhere else.

06:50.260 --> 06:56.760
So let's create an another game object for this script, because this score manager script also destroying.

06:56.800 --> 07:00.680
And we don't want that to be happen because we need the score.

07:00.720 --> 07:01.280
Sorry.

07:01.320 --> 07:04.480
We need the score manager script in other things.

07:04.480 --> 07:07.680
So that's why we're going to right click on this Score Manager script.

07:07.680 --> 07:10.000
And let's click on this remove component.

07:10.000 --> 07:14.480
And we're going to attach the Score Manager script to any other else game object.

07:14.480 --> 07:19.600
Or we can just simply create a another game object for that score manager script.

07:19.600 --> 07:21.160
So let's go to hierarchy.

07:21.160 --> 07:23.280
Let's right click or hit this plus icon.

07:23.280 --> 07:25.360
And let's create an empty game object.

07:25.360 --> 07:28.720
And I'm going to call this game object as the name of my script.

07:28.720 --> 07:30.760
So which is score Manager.

07:30.760 --> 07:32.840
So let's call it score Manager.

07:32.840 --> 07:35.640
And let's go to transform right click and reset.

07:35.640 --> 07:38.520
And I'm going to select my Score Manager game object.

07:38.520 --> 07:42.760
And I'm going to drag it on top of my hierarchy so I can see all the time.

07:42.760 --> 07:45.000
And now I'm going to select Score Manager Script.

07:45.000 --> 07:48.200
And I'm going to drag it over to this Add Component section.

07:48.240 --> 07:51.420
Now it's fine and we hope it will work fine.

07:51.420 --> 07:55.300
So let's click on this play button in the top by now and let's have a look.

07:55.300 --> 08:01.780
So by now this score manager script not gonna get destroyed because we just attach this script to other

08:01.780 --> 08:04.940
game object which we not destroying at all.

08:04.940 --> 08:06.380
So we're gonna have the score.

08:07.180 --> 08:08.820
So just wait for it to compile.

08:09.100 --> 08:09.500
Sorry.

08:09.540 --> 08:11.660
Wait for it to die.

08:11.660 --> 08:13.260
This player game object.

08:13.260 --> 08:19.820
And I really apologize for it, that we attach this score manager script instead of adding to a separate

08:19.820 --> 08:20.340
game object.

08:20.340 --> 08:26.500
We just added to this player game object and we can see, uh, player game object is dead by now.

08:26.500 --> 08:32.260
But the problem is that if we just go over to Inspector underneath our score manager script, we can

08:32.260 --> 08:34.100
see the score current score.

08:34.140 --> 08:39.260
It just keep increasing and increasing even after our player game object dies.

08:39.260 --> 08:43.300
So once our player game object dies, we need to stop increasing.

08:43.300 --> 08:46.020
So we're gonna get out of play mode to stop doing that.

08:46.020 --> 08:52.630
We do know we just created a game manager script, which is just keeping track of the player is active

08:52.630 --> 08:53.350
or not.

08:53.350 --> 08:59.790
And we do know once we destroy our player game object we just created a parameter called is Game Active

08:59.790 --> 09:03.110
and we're setting it to false once our player game object died.

09:03.110 --> 09:09.270
So if you haven't seen the lecture yet, then you can just move over to my previous lecture.

09:09.270 --> 09:16.070
In this course you and I have in that title, which says Gamemanager script in order to control the

09:16.070 --> 09:17.790
game is active or not.

09:17.790 --> 09:23.070
So if you haven't checked that out lecture, then you can go back and check the game manager script.

09:23.070 --> 09:25.030
So we're going to use that logic over here.

09:25.030 --> 09:25.870
So that's why.

09:25.910 --> 09:30.510
So let's open up our score manager script and let's double click that.

09:30.510 --> 09:32.590
And we before we add score.

09:32.710 --> 09:34.230
So we're adding over here.

09:34.230 --> 09:37.190
So before we add score we're going to check here.

09:37.310 --> 09:41.710
So we will use this if condition and make first bracket and some curly brackets.

09:41.710 --> 09:43.470
And what we want to check here.

09:43.470 --> 09:48.690
We just want to check if the player game object is uh is active or not.

09:48.730 --> 09:51.610
Or if the player game object dies, mean destroy.

09:51.930 --> 09:55.050
Uh, in that situation, we need to stop increasing.

09:55.050 --> 09:58.810
So before we keep increasing our score, we're going to check.

09:58.810 --> 09:59.810
So we will check.

09:59.850 --> 10:01.210
So we can use this.

10:01.210 --> 10:05.250
Find any object by type and make this arrows and into arrows.

10:05.250 --> 10:08.170
You need to pass the component name that you're looking for.

10:08.210 --> 10:10.170
So we're going to pass player over here.

10:10.490 --> 10:13.170
And we're going to make some first brackets.

10:13.330 --> 10:14.730
And one more first bracket.

10:14.730 --> 10:18.250
And we will check if it's equals equals to null.

10:19.090 --> 10:20.410
And null means empty.

10:20.450 --> 10:21.970
So what we basically doing.

10:21.970 --> 10:23.730
We're just going over to player skip.

10:23.730 --> 10:24.930
So you need to use this.

10:24.930 --> 10:29.410
Find any object by type and the object by type you're looking for.

10:29.410 --> 10:31.410
So you need to put in this arrows.

10:31.410 --> 10:33.650
So the script we're looking for is a player.

10:33.650 --> 10:36.370
So basically we're just going over to this player skip.

10:36.370 --> 10:41.130
And the player script is attached to this player game object we can see in the inspector.

10:41.130 --> 10:43.930
So we're checking if this player script is equals.

10:43.970 --> 10:49.310
Equals to null means we don't have any player skip in hierarchy as well as in this scene.

10:49.310 --> 10:51.830
View means our player skip get destroyed.

10:51.830 --> 10:57.150
And we do know once we destroy this player game object, this player script will also be destroyed.

10:57.150 --> 11:01.590
Because this player skip we can see is attached to this player game object.

11:01.590 --> 11:06.510
So once this player game object destroy this player Skip will also be destroyed.

11:06.510 --> 11:08.870
So what we're doing over here we checking.

11:08.910 --> 11:15.350
As you can see we're checking if player is a script is equals equals to null means we don't have any

11:15.350 --> 11:20.350
player skip in the hierarchy as well as in this interview means player game object dies.

11:20.350 --> 11:25.030
So in that moment what we need to do, we need to stop increasing our score.

11:25.030 --> 11:27.150
So that's why we're going to type this return.

11:27.150 --> 11:31.350
And we do know after return whatever we're going to do it's not going to be execute.

11:31.350 --> 11:36.750
So before we type in return what we check what we're doing, we're just checking if there is no player.

11:36.750 --> 11:38.950
Skip means the player game object dies.

11:39.310 --> 11:43.550
So if that is the case, then we're doing return, as you can see.

11:43.590 --> 11:49.290
And after return, whatever we're going to do, it's not going to be execute means our current is current

11:49.290 --> 11:51.290
score will be stuck.

11:51.490 --> 11:54.490
Uh, we're stuck at where player dies.

11:54.490 --> 11:56.730
So it's going to stuck at that point.

11:56.730 --> 11:58.330
So basically that is the thing.

11:58.330 --> 12:02.570
I hope you get the idea or what we can simply do instead of using this.

12:02.610 --> 12:05.290
We're going to use this game manager instead.

12:05.290 --> 12:09.450
So if you're not familiar with this then you can just use that one.

12:09.490 --> 12:17.170
Or if you just, uh, watch my uh, singleton uh, or clean keep uh, means, uh, clean code, uh,

12:17.170 --> 12:17.850
lecture.

12:18.170 --> 12:23.690
Uh, if you watch that, then you can just use this game manager dot instance, and we're going to access

12:23.690 --> 12:25.570
that this game at a parameter.

12:25.570 --> 12:28.410
And we're going to check if it's equals equals to false.

12:28.450 --> 12:32.810
If that is the case basically means the same thing we're doing means there is no.

12:32.810 --> 12:37.890
And we do know once we destroy our player game object, we just setting this is game active parameter

12:37.890 --> 12:38.530
to false.

12:38.530 --> 12:39.930
And we're checking over here.

12:39.930 --> 12:45.900
As you can see firstly we just moving over to camera gamemanager script, then instant, and then accessing

12:45.900 --> 12:50.100
the schematic parameter, and we're checking if it's equals equals to false.

12:50.100 --> 12:53.260
If that is the case means we don't have the player game object.

12:53.260 --> 12:58.740
Basically, once we're destroying our player game object at that moment we just are setting this is

12:58.740 --> 13:00.380
game parameter to false.

13:00.380 --> 13:02.180
And we're checking over here.

13:02.180 --> 13:09.700
So if you watch the singleton uh pattern lecture or the uh clean code lecture, then you can use or

13:09.700 --> 13:14.460
you can just simply use that which is the find any object by type as well.

13:14.460 --> 13:16.980
So I'm going to press down Ctrl S to save my script.

13:16.980 --> 13:21.340
And let's move over to unity and have a look on this.

13:28.700 --> 13:30.180
So just wait for to compile.

13:30.180 --> 13:31.500
And it's done now.

13:31.700 --> 13:36.100
So if I select my score manager script, uh sorry GameObject in the hierarchy.

13:36.380 --> 13:39.820
And let's click on this play button in the top to play our game.

13:39.820 --> 13:46.720
You will see as soon as this player GameObject just gonna destroy the current score will stop increasing

13:47.040 --> 13:50.560
because we're checking before we adding current score.

13:50.560 --> 13:52.400
So just wait for it to compile.

13:53.240 --> 13:53.680
Sorry.

13:53.800 --> 13:55.120
Wait for it to die.

13:55.600 --> 13:56.880
This player game object.

13:56.880 --> 14:01.360
So let's get closer to this enemy game object in order to take the damage.

14:01.360 --> 14:09.120
And we can see the current score is already now 160, then 70, and it's just rising and rising.

14:09.120 --> 14:14.560
But once our player game object get destroyed, we can see underneath our score manager script.

14:14.560 --> 14:19.080
The current score just stops at 203, as you can see.

14:19.080 --> 14:20.640
So we're going to get out of play mode.

14:20.640 --> 14:26.840
And what we have to do instead of showing our current score underneath our score manager script.

14:26.840 --> 14:33.680
We also need to show show this in our UI so player can know how much score they made so far.

14:34.160 --> 14:38.400
So we can just use that UI in order to show that up.

14:38.440 --> 14:43.780
So we're going to select our canvas in the hierarchy, and let's press down F in order to focus on that.

14:43.780 --> 14:45.100
And let's click over here.

14:45.100 --> 14:48.420
We're gonna move over to this UI game object.

14:48.900 --> 14:54.940
Uh, what we can simply do, we can just right click on it or on this UI game object, then go to UI

14:55.060 --> 14:56.540
and then legacy in the bottom.

14:56.540 --> 14:57.940
And then choose this text.

14:57.940 --> 15:00.900
And you can just name that text whatever you want.

15:00.940 --> 15:07.580
But instead of doing or making it from scratch, I'm going to simply duplicate this current coin at

15:07.820 --> 15:09.580
in order to make the score one.

15:09.580 --> 15:14.740
So I'm going to select that current coin text, and I'm going to press down control D in order to duplicate.

15:14.740 --> 15:18.820
And I want this to be to be moved in the top right section.

15:18.820 --> 15:19.820
So we're going to select that.

15:19.820 --> 15:23.780
But before it we're going to name it to something like uh current score text.

15:23.820 --> 15:30.340
So instead of saying current coin text I'm going to say current score current score text.

15:30.340 --> 15:32.620
So let's call it current score text.

15:32.620 --> 15:36.220
And we also want to move this one to the top right.

15:36.220 --> 15:38.460
So we're going to select that current score text.

15:38.500 --> 15:39.840
Let's inspector.

15:39.880 --> 15:42.720
So Inspector rect transform click over here.

15:42.720 --> 15:44.240
And we're going to hold down alt.

15:44.240 --> 15:46.240
And we're going to choose this top right one.

15:46.520 --> 15:53.320
And now we can see as soon as we chosen that this takes a current coin score takes just gets to the

15:53.320 --> 15:54.360
top right corner.

15:54.520 --> 16:00.520
And I want this takes to be start from a from the right side not to the left side.

16:00.600 --> 16:05.040
So what we're going to do for that we will move over to this text component in Inspector.

16:05.040 --> 16:09.880
And we're going to scroll down and alignment over here I'm going to choose the right one.

16:09.880 --> 16:11.200
So the right section.

16:11.200 --> 16:16.240
So our text will keep increasing from the right side not the left side.

16:16.240 --> 16:18.480
So you can just choose the alignment.

16:18.480 --> 16:23.880
And I'm going to move it somewhere over here a little bit up something like this much.

16:23.880 --> 16:27.080
And we can see this is this seems pretty much fine.

16:27.480 --> 16:33.040
And we can just go over to UI and we're going to move over to overrides and then click on Apply All.

16:33.160 --> 16:37.930
So what we basically need to do we need a reference of this current score cortex.

16:37.970 --> 16:43.290
Then we can just change this up with our score manager, which is our current score.

16:43.370 --> 16:49.450
So basically we just doing the same thing as we have done with current coin takes as well as our health

16:49.450 --> 16:49.850
text.

16:49.850 --> 16:52.050
So we're going to approach the same way.

16:52.170 --> 16:55.490
So let's select the Score Manager GameObject in the hierarchy.

16:55.490 --> 16:57.690
And let's open up the Score Manager script.

16:57.690 --> 17:01.290
And let's go to the top of our class and what we basically need.

17:01.330 --> 17:03.890
We need a reference of that text component.

17:03.890 --> 17:09.770
But before we use that, make sure you just go to the top of your class and include this namespace called

17:09.810 --> 17:11.890
using Unity Engine dot UI.

17:12.090 --> 17:17.650
So whenever you're working with UI, make sure you just go to the top of your class and include this

17:17.650 --> 17:20.850
namespace called using Unity Engine UI.

17:20.890 --> 17:23.210
And now we are ready to grab the reference.

17:23.210 --> 17:25.490
So I'm going to make a another serialized field.

17:25.490 --> 17:27.810
So let's make a serialized field.

17:27.970 --> 17:31.730
And that will private private.

17:31.730 --> 17:34.810
And the component we are looking for is text type.

17:34.810 --> 17:39.750
So we're going to type this text and I'm going to call it something like current coin text current.

17:39.790 --> 17:42.150
Sorry not coin I'm really apologize.

17:42.190 --> 17:43.390
Current score text.

17:43.430 --> 17:46.790
It should be current score text I'm going to call.

17:46.790 --> 17:48.670
And let's close that up with semicolon.

17:48.670 --> 17:51.350
And we're going to press down Ctrl S to save our script.

17:51.350 --> 17:53.070
And let's move over to unity.

17:53.070 --> 17:58.990
So underneath our score manager script we're going to able to see a current score takes a parameter

17:58.990 --> 18:00.190
or a slot.

18:00.230 --> 18:05.550
So what we need to do there we need to drag this current score takes a game object into that slot.

18:05.590 --> 18:06.950
So we're going to have the reference.

18:06.950 --> 18:11.070
So I'm going to select our current score text underneath our canvas game object.

18:11.070 --> 18:15.990
And we're going to select that and drag it over to this slot says Current Score Text.

18:15.990 --> 18:20.990
And we can see by now we have the reference called current score text text reference.

18:20.990 --> 18:25.870
So basically we basically have this current score text or this text component reference.

18:25.870 --> 18:31.190
And now we are ready to link this up with our current score.

18:31.190 --> 18:36.410
So let's open up our Score Manager script and let's move over to this update function.

18:36.410 --> 18:38.850
So update function runs every single frame.

18:38.850 --> 18:42.970
So every single frame we also want to show up or we're gonna change.

18:42.970 --> 18:46.610
But this is not a perfect way uh perfect way.

18:46.650 --> 18:49.810
But it it's fine if it's, uh.

18:50.450 --> 18:55.610
So let's do it inside this, uh, inside over here instead of doing here.

18:55.610 --> 18:56.770
So what we're going to do.

18:56.770 --> 19:01.690
So over here, as you can see, we're checking if the player game object is active or not.

19:01.730 --> 19:07.090
Means if the player game object dies, then what we're doing, we just, uh, typing return, as you

19:07.090 --> 19:07.610
can see.

19:07.930 --> 19:14.370
Or as we just saying return, or we can simply do outside if this if condition as well.

19:14.370 --> 19:15.730
So let's do outside.

19:15.730 --> 19:21.450
So it's going to be much uh easy to understand instead of doing inside this if condition.

19:21.450 --> 19:24.730
So what we're going to do now, we're going to move over to current score text.

19:24.730 --> 19:26.650
And then we're going to access the text.

19:26.650 --> 19:29.890
And we will set the text equal to our current score.

19:29.890 --> 19:32.010
And let's close that up with semicolon.

19:32.010 --> 19:37.940
So the current score As you can see over here is a float parameter and this current score.

19:38.260 --> 19:39.260
Tex dot text.

19:39.300 --> 19:41.820
Right over here is a string parameter.

19:41.820 --> 19:48.220
So what we need to do we need to convert this float parameter, this current score in order into a string.

19:48.220 --> 19:53.820
And in order to convert that we basically have to use these two, uh two string dot two string and then

19:53.820 --> 19:55.380
close that off with semicolon.

19:55.380 --> 19:59.140
And we're going to press down Ctrl S to save our score, uh code.

19:59.180 --> 20:00.460
And let's move to unity.

20:00.460 --> 20:05.660
So basically what we're doing, we're just going over to this current score text game object and then

20:05.660 --> 20:06.620
accessing the text.

20:06.620 --> 20:09.580
And we're setting the text equal to our current score.

20:09.580 --> 20:12.420
So let's suppose current score over here is ten.

20:12.420 --> 20:16.740
So the current score text dot text right over here is just going to be ten right away.

20:16.740 --> 20:16.940
Why.

20:16.980 --> 20:19.500
Because we're directly setting it as you can see.

20:19.500 --> 20:23.540
So we simply moving over to this current score text game object.

20:23.540 --> 20:25.500
And then we accessing this text.

20:25.500 --> 20:28.500
And we're setting this text equal to our current score.

20:28.500 --> 20:34.120
So it's just going to be update with our current score or the score that we made so far.

20:34.240 --> 20:38.040
So let's go to unity by now and have a look on this.

20:38.520 --> 20:40.960
So we're going to click on this play button in the top.

20:40.960 --> 20:45.600
And you will see as soon as the current score just keep increasing.

20:45.720 --> 20:50.600
The current score takes will also just going to increase with our current score.

20:51.000 --> 20:53.000
So as you can see it just screen.

20:53.000 --> 20:57.280
But the problem is that there is a floating number or this decimal number.

20:57.280 --> 20:58.440
So we don't want that.

20:58.440 --> 21:02.480
Instead we just want to be a whole number like 7080, 90.

21:02.480 --> 21:06.120
And the list just goes on instead of decimal places.

21:06.120 --> 21:07.600
So we're going to get out of play mode.

21:07.600 --> 21:12.840
And in order to do that, what we basically have to do, we need to move over to this script.

21:12.840 --> 21:19.440
And over here, when you just converting that float parameter into a string, then you can just put

21:19.440 --> 21:23.360
in this first bracket right over here in quotation.

21:24.200 --> 21:26.520
In quotation you need to pass this zero.

21:26.720 --> 21:33.340
And once you pass in between this quotation zero it's going to convert that decimal numbers into a whole

21:33.340 --> 21:38.220
number, or basically it's just going to show up the whole numbers, not the decimal places.

21:38.220 --> 21:39.820
So make sure you just do that.

21:39.820 --> 21:41.820
Firstly, you need to make this quotation.

21:41.820 --> 21:45.940
And in between this quotation you need to pass zero, uh, the whole number.

21:45.940 --> 21:50.780
So make sure you just do that and uh, use this uh, current score dot.

21:50.820 --> 21:56.860
Uh, basically this dot two string function in order to convert that float parameter into a string.

21:56.860 --> 21:59.660
Now we're going to press down Ctrl S to save our script.

21:59.660 --> 22:02.020
And now let's move over to unity.

22:02.020 --> 22:07.620
So by now we should be able to see only whole numbers not the decimal places at all.

22:07.620 --> 22:11.860
So let's have a look on this and we will see that.

22:13.340 --> 22:17.460
And let's click on this play button in the top by now and have a look.

22:17.500 --> 22:20.100
And you can increase the amount as well.

22:20.100 --> 22:26.460
If you just want to increase your current score too much fast way, then you can just increase the amount

22:26.500 --> 22:27.980
parameter as well.

22:27.980 --> 22:34.400
So now as soon as the game started, we can see the current score just increasing and the score is now

22:34.400 --> 22:39.800
in whole numbers, not in decimal places, and that seems pretty much fine.

22:39.800 --> 22:45.920
So let's take damage from this, uh, enemy game object, and we will see as soon as this player game

22:45.960 --> 22:48.920
object is just gonna lose all of his health.

22:48.960 --> 22:54.800
We can see, uh, this current score or the current score just stops increasing.

22:54.800 --> 23:00.960
And we can see in the UI as well over here underneath our canvas game object.

23:00.960 --> 23:03.040
So basically, that is the pretty cool thing.

23:03.040 --> 23:10.400
I hope you get the idea that how you can do it, or how you can show up the score that you just created

23:10.400 --> 23:15.520
in the UI, so you can just do that in order by creating a separate script.

23:15.560 --> 23:16.800
I hope you get the idea.

23:16.800 --> 23:22.640
So I'm going to get out of play mode and we will go to UI Game Object Overrides in Inspector, and we're

23:22.640 --> 23:28.770
going to click on this apply All and as well we're going to make this Score Manager script This one.

23:28.810 --> 23:29.210
Sorry.

23:29.250 --> 23:29.810
Not.

23:29.850 --> 23:31.570
I'm really apologize for it.

23:31.610 --> 23:36.690
Instead, we this score manager game object and we're going to make this one a prefab.

23:36.690 --> 23:38.130
So we're going to have the copy.

23:38.130 --> 23:41.250
So let's select the Score Manager game object in the hierarchy.

23:41.250 --> 23:46.010
And let's drag it over to this prefab folder in order to make it a prefab.

23:46.050 --> 23:50.690
So I'm going to move uh I'm going to drag it over to this objects uh sub folder.

23:51.010 --> 23:53.730
Uh, this objects uh prefab sub folder.

23:53.730 --> 23:58.250
You can simply say and let's press down Ctrl s to save our script.

23:58.490 --> 24:04.570
And make sure you just attach that score manager script to a other game object, not in specifically

24:04.570 --> 24:07.370
to this player game object, because we're destroying that.

24:07.370 --> 24:12.810
So we're also going to lose our score manager script once we destroy our player game object.

24:12.810 --> 24:17.450
So that's why we just created a separate game object for that score manager script.

24:17.450 --> 24:18.610
And we just attach.

24:18.610 --> 24:23.050
Or you can just attach to any game object, make sure it's, uh, don't get destroyed.

24:23.050 --> 24:25.450
So you can simply attach it right away.

24:25.570 --> 24:27.330
So basically that is the thing.
