WEBVTT

00:00.080 --> 00:04.720
We also need to show up the high score that we made inside our game over UI.

00:04.840 --> 00:09.320
So I'm gonna make my player health a little bit low for testing purposes.

00:09.320 --> 00:13.960
So I'm gonna move over to my hierarchy and let's select this player game object.

00:14.120 --> 00:16.280
Let's go to player Skip in Inspector.

00:16.280 --> 00:19.000
And I'm going to make the max health something like one.

00:19.000 --> 00:20.600
And I'm going to speed up.

00:20.640 --> 00:27.320
I'm gonna make I'm gonna increase this speed of player game object something like five for testing purposes.

00:27.480 --> 00:29.560
And let's click on this play button in the top.

00:29.560 --> 00:34.520
By now you will see that our player game object just gonna move a little bit faster.

00:34.560 --> 00:37.160
And the max health of player we set one.

00:37.160 --> 00:42.600
So if we just take one damage right away this player game object just gonna loses all of his health

00:42.600 --> 00:45.480
and then die function just gonna call right away.

00:45.480 --> 00:54.240
So let's have a look on this and we can see player game object just died and the high score is set to

00:54.280 --> 00:54.800
zero.

00:54.800 --> 00:59.230
So we also need to, uh, need to show up the high score that we made met.

00:59.270 --> 01:04.590
If our current score is greater than previous high score, then we're going to make that current score

01:04.630 --> 01:05.910
as a new high score.

01:05.990 --> 01:10.510
So let's get out of play mode and we're going to open up our score manager script.

01:11.070 --> 01:13.750
Inside that script we're just doing those things.

01:14.310 --> 01:17.910
So I'm going to select my Score Manager GameObject in the hierarchy.

01:17.910 --> 01:23.430
And let's open up the Score Manager script quickly quickly by double clicking on it.

01:23.430 --> 01:28.950
So what we basically need to have we need to have a reference of that high score text.

01:29.310 --> 01:36.070
So if I move over to hierarchy, then canvas, then game over UI and we can see we have made a high

01:36.110 --> 01:36.510
score.

01:36.550 --> 01:42.830
As you can see, if I just enable this, we can see we need a reference of this zero text, basically

01:42.870 --> 01:43.750
our high score.

01:43.870 --> 01:45.950
So we need a reference of this text.

01:45.950 --> 01:49.510
Then we can just show that up in our UI.

01:49.550 --> 01:51.230
So let's go to script.

01:51.230 --> 01:52.990
And we're going to make over here.

01:52.990 --> 01:56.870
So let's make a another serialized field that will be private.

01:56.870 --> 01:59.470
And the component we're looking for is a text type.

01:59.470 --> 02:00.990
So we're going to type this text.

02:00.990 --> 02:06.430
But before you type text make sure you just go to the top of your class and include this namespace called

02:06.470 --> 02:08.710
using Unityengine.ui.

02:08.750 --> 02:13.910
So whenever we're going to work with UI, make sure you just go to the top of your class and include

02:13.910 --> 02:14.990
this namespace.

02:15.350 --> 02:18.590
And I'm going to call this one something like Highscore text.

02:18.590 --> 02:22.310
So let's call it high score high score text.

02:22.310 --> 02:24.270
And let's close that up with semicolon.

02:24.270 --> 02:26.750
And we're going to press down Ctrl S to save script.

02:26.750 --> 02:28.070
And let's move to unity.

02:28.390 --> 02:35.070
So we need to drag the reference in that slot underneath our score Manager script.

02:35.350 --> 02:36.870
So just wait for to compile.

02:36.870 --> 02:39.590
And we need to drag the reference in that slot.

02:39.630 --> 02:43.790
Then we can just update the score in our high score.

02:43.910 --> 02:49.790
So now if I select my Score Manager GameObject in the hierarchy underneath our Score Manager script,

02:49.790 --> 02:52.550
we can see high score text and it says none text.

02:52.550 --> 02:55.030
So what we're going to do, we're going to select this text.

02:55.030 --> 02:56.820
And we're going to drag in that slot.

02:56.860 --> 02:57.940
Our high score tech.

02:57.940 --> 02:59.380
So I'm going to select my high score.

02:59.420 --> 03:01.100
Let's drag it into that slot.

03:01.100 --> 03:03.100
And now we can see we have the reference.

03:03.100 --> 03:06.500
Basically we have this high high score text reference.

03:06.500 --> 03:10.900
And we are ready to update our high score into this high score text.

03:10.940 --> 03:13.580
So let's open up our script by quickly.

03:13.860 --> 03:16.420
And I'm going to move over to this start function.

03:16.420 --> 03:19.140
So start function get call in the start of the game.

03:19.140 --> 03:24.060
And we do know once we start our game we're not going to have our score.

03:24.060 --> 03:26.500
So what we're going to do we're going to update the text.

03:26.500 --> 03:28.940
So we will move over to high score text.

03:28.940 --> 03:30.700
And then we're going to access the text.

03:30.700 --> 03:34.220
And we will set equal to the text player preps.

03:34.220 --> 03:38.580
Basically we're going to use player preps in order to save uh our high score.

03:38.620 --> 03:43.940
This is unity in build system in order to save, uh save our score.

03:44.020 --> 03:50.340
And if you just want to jump into more complex, uh, then, uh, then you can just go to YouTube.

03:50.540 --> 03:57.370
Uh, if you just want to save multiple datas, uh, then you should not use this one as, but for beginners

03:57.370 --> 03:58.650
it's pretty much fine.

03:58.650 --> 04:03.610
So basically what we're doing, we're just going over to this high score, basically this one and then

04:03.650 --> 04:05.890
accessing this text as you can see.

04:05.930 --> 04:07.930
And we're setting the text equal to.

04:08.050 --> 04:10.010
So we're going to use this playerprefs.

04:10.010 --> 04:12.130
So we need to use this Playerprefs.

04:12.290 --> 04:16.130
And we do know in the start of the game we're not going to have any score.

04:16.130 --> 04:21.130
So we're going to use this get float function and this get float function as a first argument.

04:21.130 --> 04:25.010
It's going to take the key or which key you just want to save.

04:25.050 --> 04:26.610
So we're going to create a key.

04:26.770 --> 04:31.010
And you need to create the key in this app in between this quotation.

04:31.010 --> 04:33.490
Because this is just going to have a string.

04:33.490 --> 04:39.290
And I'm going to call it something like high score or, or all of these letters in capital letters and

04:39.290 --> 04:39.810
comma.

04:39.810 --> 04:42.530
And the second thing you need to set the value.

04:42.530 --> 04:49.250
So once we start our game or we play our game for the first time, we're not gonna have any score.

04:49.250 --> 04:51.290
So that's why we're going to put zero f.

04:51.330 --> 04:53.850
And now we're going to close that off with a semicolon.

04:53.850 --> 04:57.810
So this high score text dot text over here is a string parameter.

04:58.250 --> 05:00.890
And this over here is a float parameter.

05:00.890 --> 05:06.650
And we can see that we cannot implicitly convert type float to string.

05:06.650 --> 05:08.410
So what we basically have to do.

05:08.410 --> 05:10.850
So this is our float parameter.

05:10.850 --> 05:14.570
So we need to convert this float into a string and into a string.

05:14.570 --> 05:18.210
In order to convert we just have to use this two string function.

05:18.210 --> 05:20.050
And it's going to convert that.

05:20.050 --> 05:22.770
So we're doing inside this start function.

05:22.770 --> 05:25.410
So start function get call in the start of the game.

05:25.410 --> 05:31.130
So in the start of the game what we're doing we're just updating our Highscore text equal to Playerprefs

05:31.130 --> 05:32.050
dot get float.

05:32.050 --> 05:37.730
So we're using this function Playerprefs dot get float in order to get our default high score.

05:37.970 --> 05:40.610
So and we also need to set the score by now.

05:40.610 --> 05:43.290
So we're going to move over to this update function.

05:43.290 --> 05:48.210
So basically what we're doing we're just going over to this Highscore text and then accessing this text.

05:48.250 --> 05:54.000
And we're setting this text equal to this Playerprefs dot get getfloat and we're just saving or getting

05:54.040 --> 05:57.080
the data from this high score key.

05:57.120 --> 05:58.160
As you can see.

05:58.160 --> 06:01.080
So later on we're going to save our data in this key.

06:01.120 --> 06:03.360
And the default value we set it to zero.

06:03.400 --> 06:07.320
So that's why this high score text dot text that's going to be zero right away.

06:07.360 --> 06:08.280
So let's have a look.

06:08.280 --> 06:11.160
So I'm gonna press Ctrl s to save my script.

06:11.160 --> 06:12.360
And let's go to unity.

06:12.520 --> 06:20.160
So once we start our game or we play our game you will see the default value of that high score just

06:20.160 --> 06:22.640
gonna be zero because we're doing over here.

06:22.680 --> 06:27.920
As you can see a gate float and we just giving the default value which is zero.

06:28.080 --> 06:30.440
So let's go to unity now.

06:30.640 --> 06:33.120
And I'm going to click on this play button in the top.

06:33.120 --> 06:38.760
But before I do I'm going to deactivate this game over UI by default.

06:38.760 --> 06:41.280
And let's click on this play button in the top.

06:41.680 --> 06:47.280
So once our player game object just gonna die, you will see the high score just gonna be zero.

06:47.280 --> 06:49.760
Because in the start of the game we're just getting kidding.

06:49.840 --> 06:53.320
Giving a default value which is zero in our eyes.

06:53.320 --> 06:54.080
Cortex.

06:57.160 --> 07:01.320
So let's take damage and we can say high score is now zero.

07:01.320 --> 07:04.640
And the current score we made so far is a 75.

07:04.640 --> 07:11.080
So what we basically have to do, we need to set this as 75 or this current score as a new high score.

07:11.120 --> 07:18.120
Because this current score we can see is greater than our previous high score, which is zero, or our

07:18.120 --> 07:19.200
starting high score.

07:19.200 --> 07:25.760
So we need to set this current score as a new high score because this current score is greater than

07:25.800 --> 07:27.240
our previous high score.

07:27.240 --> 07:30.880
So that's why we need to set this current score as a new high score.

07:30.880 --> 07:33.800
So let's get out of play mode and let's go to update function.

07:33.800 --> 07:35.000
Where we doing.

07:35.000 --> 07:36.480
So we doing over here.

07:36.960 --> 07:39.360
So we just updating our current score.

07:39.480 --> 07:41.400
And also over here what we're going to do.

07:41.440 --> 07:43.920
We're going to update the high score as well.

07:43.920 --> 07:47.120
So we will set our current score as a new high score.

07:47.120 --> 07:53.230
But before we set our current score as a new high score, we need to check if this current score is

07:53.230 --> 07:54.750
greater than previous high score.

07:54.790 --> 08:00.510
Let's suppose a previous high score is something like zero, and the current score we made five.

08:00.550 --> 08:05.510
So we do know that our current score is greater than our previous high score.

08:05.550 --> 08:09.310
Basically previous high score is zero and the current score is five.

08:09.310 --> 08:12.030
And we do know that five is greater than zero.

08:12.030 --> 08:13.790
So that's why that current score.

08:13.830 --> 08:15.950
We need to set as a new high score.

08:15.990 --> 08:18.710
So before we set the high score we're going to check over here.

08:18.710 --> 08:23.070
So we're going to use this if condition and make first bracket and some curly brackets.

08:23.070 --> 08:25.110
And what we want to check over here.

08:25.110 --> 08:26.110
We just want to check.

08:26.110 --> 08:27.870
So we're going to take our current score.

08:27.870 --> 08:31.870
And we will check if if our current score is greater than.

08:31.910 --> 08:36.590
So we're going to use this Playerprefs in order to get the default value or default.

08:36.710 --> 08:38.950
Uh sorry previous high score.

08:38.950 --> 08:41.110
So we need to use this Playerprefs.

08:41.110 --> 08:44.910
And we're going to use this get float function and this get float function.

08:44.910 --> 08:48.340
It's going to take as a first argument the key and which key?

08:48.380 --> 08:49.820
You just saving your data.

08:49.860 --> 08:52.820
So in our case we're gonna type this high score.

08:52.820 --> 08:54.900
So make sure you just spelling it correct.

08:54.900 --> 08:58.540
Because we're just getting the default value in this high score key.

08:58.580 --> 09:00.780
As you can see in this start function.

09:00.780 --> 09:02.220
So we're going to save our data.

09:02.220 --> 09:06.300
Or we're going to get the previous high score by using this high score key.

09:06.340 --> 09:07.580
Or where we're saving.

09:07.780 --> 09:12.380
So high score and the default value is just going to be zero or the previous score.

09:12.420 --> 09:14.180
Or you can just leave it like this.

09:14.220 --> 09:16.220
It's basically means what we're doing.

09:16.220 --> 09:20.700
We're just checking if our current score is greater than Playerprefs dot get float.

09:20.740 --> 09:24.140
High score basically means previous high score.

09:24.300 --> 09:28.780
So if it's greater than then we need to set this current score as a new high score.

09:28.820 --> 09:33.900
Because this current score is greater than our previous high score and the high score we're getting

09:34.220 --> 09:38.100
from this high score key, as you can see in between this question.

09:38.100 --> 09:42.740
So make sure you just put in between this quotation and you spell it correct.

09:42.780 --> 09:48.620
The key we key in which key you just are getting or setting the value.

09:48.740 --> 09:50.140
And now what we have to do.

09:50.140 --> 09:55.620
We need to set this current score as a new high score, because this current score is greater than our

09:55.620 --> 09:56.780
previous high score.

09:56.940 --> 10:02.220
And in order to set this current score as a new high score, what we have to do, we need to use this

10:02.220 --> 10:03.660
Playerprefs function.

10:03.780 --> 10:05.540
So we're going to use this Playerprefs.

10:05.580 --> 10:12.540
And to set the parameter or this current score as a new high score, we need to use this set float function.

10:12.540 --> 10:15.140
And this set float function as a first argument.

10:15.140 --> 10:19.020
It's going to take the key in which key you just want to save your data.

10:19.060 --> 10:22.060
So we're going to save our data in this high score key.

10:22.100 --> 10:23.100
As you can see.

10:23.500 --> 10:26.020
So we're going to make first a quotation.

10:26.020 --> 10:28.780
And then we're going to pass the key which is our high score.

10:28.860 --> 10:32.460
And the second thing you need to pass the score that you want to set.

10:32.500 --> 10:36.580
So we're going to pass this current score Y is going to set the y y.

10:36.580 --> 10:38.180
We're going to pass this current score.

10:38.220 --> 10:42.580
Because this current score as you can see is greater than our previous high score.

10:42.580 --> 10:46.570
So that's why we just want to set this current score as a new high score.

10:46.570 --> 10:49.970
So we're going to pass our current score as a second parameter.

10:49.970 --> 10:52.450
And now we're going to close that off with semicolon.

10:53.570 --> 10:59.050
And as you can see firstly we're checking if our current score is greater than our previous high score.

10:59.090 --> 11:01.770
So let's suppose the current score is something like two.

11:01.810 --> 11:04.090
And the previous high score is one.

11:04.090 --> 11:06.250
And we're checking over here as you can see.

11:06.250 --> 11:07.570
So this one is two.

11:07.610 --> 11:09.330
So two greater than one.

11:09.330 --> 11:15.010
So so what we're doing in in that moment we're just setting that current score as a new high score.

11:15.050 --> 11:17.050
Basically current score is now two.

11:17.170 --> 11:20.170
So we're setting this two as a new high score.

11:20.210 --> 11:26.130
As you can see we're using this set float function in order to set the new high score.

11:26.210 --> 11:29.410
So we just assume it to but it can be any number.

11:29.410 --> 11:34.530
And after that what we have to do we need to update our high score text as well.

11:34.530 --> 11:41.450
So if we move over to unity and then set this game over UI, we just want to update that current score

11:41.490 --> 11:42.640
as a new high score.

11:42.640 --> 11:50.400
So we also need to, uh, show up in our UI that how much score we made so far or that score as a new

11:50.440 --> 11:50.920
high score.

11:50.920 --> 11:55.320
So we also need to update this high score text with our new high score.

11:55.320 --> 11:57.360
So what we will do, we will go to script.

11:57.360 --> 12:02.280
And after setting that current score as a new high score, we're going to update in the UA as well.

12:02.280 --> 12:03.960
So we will go to high score text.

12:03.960 --> 12:05.640
And now we're going to access the text.

12:05.640 --> 12:08.520
And we will set equal to text our current score.

12:08.560 --> 12:11.640
Because this current score by now as a new high score.

12:11.640 --> 12:13.520
And let's close that up with semicolon.

12:13.520 --> 12:16.760
So this current score we can see is a float parameter.

12:16.760 --> 12:20.720
And this one high score dot text dot text is a string parameter.

12:20.720 --> 12:23.880
So we need to convert this float parameter into a string.

12:23.880 --> 12:28.040
And to convert that we just basically have to use this dot two string.

12:28.040 --> 12:28.880
And that's it.

12:28.920 --> 12:31.760
And now we're going to press Ctrl S to save our script.

12:31.760 --> 12:33.640
And let's move over to unity.

12:33.920 --> 12:35.680
And you will see that.

12:37.160 --> 12:43.240
So as soon as our current score is going to be a new, uh, basically greater than our previous high

12:43.280 --> 12:43.680
score.

12:43.840 --> 12:44.840
Than current score.

12:44.840 --> 12:47.000
Just going to be a new high score.

12:47.000 --> 12:52.400
So basically what we're doing, we're just going over to this, uh, sorry, this high score and then

12:52.400 --> 12:58.120
accessing this text of this high score, and we're setting this text equal to our new current score,

12:58.160 --> 13:02.800
the high score we set as a new high score, which is current score, as you can see.

13:02.800 --> 13:04.880
So I hope you get the idea of this.

13:04.920 --> 13:11.480
And if you still a little bit confused then of course I will give a another video link in the description,

13:11.600 --> 13:13.160
uh, description as well.

13:13.160 --> 13:19.520
So sorry, I'm not gonna put it in description, but I'm gonna give a, I'm gonna give in these resources

13:19.520 --> 13:24.360
the link so you can go and check that out if you just want to learn more deeply.

13:24.560 --> 13:30.240
And let's go to unity and make sure you just press down Ctrl S to save your script and then move to

13:30.280 --> 13:30.800
unity.

13:31.000 --> 13:37.280
And by default, I'm gonna deactivate or just gonna set active to false this game over and let's have

13:37.280 --> 13:37.520
a look.

13:37.520 --> 13:42.510
So I'm going to click on this play button in the top to play my game, and let's see if the high score

13:42.550 --> 13:44.830
just getting updated as a new high score.

13:44.910 --> 13:50.550
So if our current score is greater than previous high score, then that current score is just going

13:50.550 --> 13:52.270
to be set as a new high score.

13:53.430 --> 13:55.270
So let's have a look on this.

13:55.710 --> 13:57.790
So oh okay.

13:57.950 --> 14:00.270
So we so I'm going to get out of play mode.

14:00.630 --> 14:05.070
And if I just play click on this play button in the top.

14:05.110 --> 14:09.510
You will see that our current score is just going to be a new high score.

14:10.310 --> 14:13.070
Uh, I guess we met around 93.

14:13.470 --> 14:14.630
Uh, so let's have a look.

14:14.630 --> 14:19.790
So I'm going to take damage from this enemy game object and you will see.

14:21.670 --> 14:26.990
And we can see that high score is 93 because we previously made 93.

14:27.030 --> 14:31.350
Our high score and the current score is we can see is 75.

14:31.350 --> 14:35.110
So that's why this current score is not set to new high score.

14:35.150 --> 14:40.340
Basically this current score is not greater than our previous high score, which is 93.

14:40.500 --> 14:44.180
And we do know that 75 is not greater than 93.

14:44.180 --> 14:48.300
So that's why this current score not set it to as a new high score.

14:48.300 --> 14:54.220
But if the current score is greater than greater than our previous high score, you will see the high

14:54.260 --> 15:00.260
score just going to be updated with our new, uh, basically new score, new high score.

15:00.260 --> 15:06.460
So let's get out of play mode and let's make a number or score something around 100, because that 100

15:06.460 --> 15:08.460
is just going to be greater than 93.

15:08.460 --> 15:13.660
And we should see that current score that we made which is 100 or greater than 100 number.

15:13.940 --> 15:15.860
Uh, it's going to save as a new high score.

15:15.860 --> 15:17.060
So let's check that out.

15:17.060 --> 15:18.460
So I'm going to get out of play.

15:18.580 --> 15:22.980
I'm going to click on this play button in the top in order to check it one more time.

15:26.980 --> 15:28.180
So let's have a look.

15:29.940 --> 15:32.980
And we're going to do that I'm going to take damage.

15:33.820 --> 15:34.700
Sorry.

15:35.300 --> 15:37.540
And and we should see.

15:37.540 --> 15:43.860
So we made our current score something like 130 as you can see, or 150.

15:43.860 --> 15:45.300
So I'm going to get out of play mode.

15:45.380 --> 15:45.620
Now.

15:45.620 --> 15:48.100
This current score should be as a new high score.

15:48.100 --> 15:50.740
So I'm going to click on this play button in the top by now.

15:50.740 --> 15:51.940
And I'm going to die.

15:52.100 --> 15:58.060
And we should see that current score that we made which is 150 should be as a new high score because

15:58.060 --> 16:03.180
that number is our greater than previous high score, which is which was 93.

16:03.180 --> 16:06.180
And we do know 150 is greater than 93.

16:06.180 --> 16:08.340
So it's going to be saved as a new high score.

16:08.340 --> 16:12.660
And we can indeed see that high score is 167 as we made.

16:12.660 --> 16:20.180
And the current score is 76, and the 76 is not a greater than our previous high score or uh, that

16:20.180 --> 16:20.980
93.

16:20.980 --> 16:25.780
So that's why 167 is just set it to as a new high score.

16:25.780 --> 16:27.180
So I'm going to get out of play mode.

16:27.180 --> 16:33.500
But before I get out of play mode, we can see our high score is safe or this text just gets updated

16:33.500 --> 16:35.330
with decimal places.

16:35.330 --> 16:41.210
So to get rid of this decimal places, what we basically have to do in quotation, we just need to pass

16:41.250 --> 16:41.770
zero.

16:41.770 --> 16:43.170
So let's get out of play mode.

16:43.170 --> 16:45.170
And if we move over to unity.

16:45.170 --> 16:47.850
So we're just setting as you can see two string.

16:47.850 --> 16:54.930
So over here what we basically have to do once we convert this float parameter into a string, you have

16:54.930 --> 16:57.250
to put this quotation.

16:57.250 --> 17:01.650
And in this code between this quotation you just need to pass the zero f.

17:01.810 --> 17:03.770
So this is just going to be ah.

17:03.890 --> 17:09.730
So it will just ignore those decimal places or that floating numbers and it's gonna show up the whole

17:09.730 --> 17:10.970
numbers instead.

17:11.010 --> 17:14.770
Now I'm going to press down Ctrl s to save my script.

17:14.770 --> 17:17.570
And let's move over to unity one more time.

17:17.570 --> 17:24.730
And we should be able to see we should see that those decimal places are just gonna be out, uh, from

17:24.930 --> 17:26.290
our high score text.

17:26.290 --> 17:27.850
So let's have a look on this.

17:27.850 --> 17:30.490
So I'm going to click on this play button in the top by now.

17:30.490 --> 17:32.170
And let's have a look on this.

17:32.170 --> 17:32.320
Is.

17:40.000 --> 17:43.240
So let's take damage from that anime game object.

17:44.720 --> 17:46.240
This anime game object.

17:47.080 --> 17:52.640
So one two and we can see we still able to see high score one, six and seven.

17:52.640 --> 17:55.360
Basically what we have to do, we need to get out of play mode.

17:55.360 --> 17:58.560
And we also need to make this one in the start of the game.

17:58.560 --> 18:00.240
As you can see, we just sitting.

18:00.240 --> 18:06.760
So once we convert this float parameter into a string, we need to put inside this quotation as well.

18:06.760 --> 18:07.520
Then zero.

18:07.520 --> 18:09.320
So make sure you just do that.

18:09.600 --> 18:12.000
And I'm going to remove this f instead.

18:12.000 --> 18:18.600
So make sure you once you're converting a float parameter or a integer parameter into a string, make

18:18.640 --> 18:21.640
sure in between this quotation you just pass zero.

18:21.640 --> 18:24.320
So it's going to ignore the decimal places.

18:24.320 --> 18:29.160
So I'm going to press down ctrl s one more time in in order to save my script.

18:29.320 --> 18:35.560
So we need to do both of those sites and we forgot to do or it was left behind.

18:35.560 --> 18:41.920
So that's why we need to move over to script, and we need to put it in quotation zero as well to that.

18:41.920 --> 18:44.400
So I'm going to click on this play button in the top.

18:44.520 --> 18:46.800
And it should be fine by now.

18:46.840 --> 18:50.720
If it's not uh then uh I guess it should be fine.

18:50.720 --> 18:53.280
So you can go with decimal places as well.

18:53.280 --> 18:54.560
It's totally up to you.

18:54.960 --> 18:57.200
Uh, but before we do, let's have a look.

18:57.200 --> 19:03.360
So we gonna ignore those decimal places or those floating numbers as soon as we're gonna have.

19:03.360 --> 19:08.600
So we can see the high score by now is 168, uh, 168.

19:08.600 --> 19:14.120
And it's not, uh, with our decimal places, so we can only see our whole numbers.

19:14.160 --> 19:17.760
Whole numbers like one, six, eight, naught point and the blah, blah.

19:17.880 --> 19:19.280
So basically that is the thing.

19:19.280 --> 19:20.880
And I'm going to get out of play mode.

19:20.880 --> 19:24.160
And let's suppose you just want to delete the high score you made.

19:24.360 --> 19:26.720
Uh, made you just want to reset that.

19:26.720 --> 19:28.080
So what you have to do.

19:28.080 --> 19:29.790
So we're gonna get out of play mode.

19:29.790 --> 19:34.830
And in order to do that, we're going to move over to script and we're going to make a function in the

19:34.830 --> 19:36.710
bottom something over here.

19:36.990 --> 19:39.070
And for function we're going to type void.

19:39.110 --> 19:40.510
And we have to name the function.

19:40.510 --> 19:48.670
So I'm going to call it gonna call I'm going to call it uh delete delete high score something like that

19:48.670 --> 19:50.150
I'm going to call that function.

19:50.150 --> 19:53.070
And let's make first bracket and some curly brackets.

19:53.070 --> 19:58.750
So what I want to do inside this function, I just want to delete the high score I just made.

19:58.790 --> 20:01.070
Or I just want to reset the high score.

20:01.070 --> 20:07.830
So in order to reset the high score you need to use this player preps player preps dot delete all.

20:07.830 --> 20:12.550
So if you use delete all then first bracket and then close it up with semicolon.

20:12.550 --> 20:15.070
It will delete all of the saving data.

20:15.070 --> 20:22.670
So let's suppose you uh use another thing to save a besides uh, as besides with this high score as

20:22.670 --> 20:25.510
well, you just saving another more data.

20:25.510 --> 20:29.070
It can be something like, uh, health mana or something like that.

20:29.110 --> 20:31.870
It was also just going to be, uh, delayed.

20:31.870 --> 20:38.510
But let's suppose you just want to delete specific, uh, data, something like this high score.

20:38.630 --> 20:41.750
Then you can use this, uh, delete key function.

20:41.790 --> 20:42.950
Delete key function.

20:42.950 --> 20:44.430
And this function, it's back.

20:44.630 --> 20:48.190
It's going to take the key that you want to delete.

20:48.190 --> 20:52.950
So I'm going to pass delete key and make sure you making first packets.

20:52.990 --> 20:59.190
And in this quotation in brackets in a string you need to pass the key in which key you just saved your

20:59.190 --> 20:59.750
data.

20:59.750 --> 21:02.670
So in our case we're going to pass in quotation high score.

21:02.830 --> 21:04.990
So I want to delete the high score.

21:05.110 --> 21:10.870
So that's why you need to put the key in between this quotation in which key you saving data.

21:10.870 --> 21:14.310
So in my case I'm just saving my data in this high score.

21:14.310 --> 21:18.990
And I just want to delete my high score or want to reset my high score.

21:18.990 --> 21:24.830
So that's why we need to pass in in quotation the key and make sure you just close that up with semicolon.

21:24.830 --> 21:29.860
And also after deleting the key, we need to update in this high score as well.

21:30.020 --> 21:33.020
Or that high score we uh, we seen.

21:33.020 --> 21:34.980
So we also need to update that.

21:34.980 --> 21:40.260
So after deleting we're going to say high score, high score text dot text.

21:40.260 --> 21:44.020
And we're going to set equal to zero as zero.

21:44.020 --> 21:49.540
So make sure you just pass this quotation and then pass this zero inside this quotation.

21:49.540 --> 21:53.460
Because this uh this right over here is a string parameter.

21:53.660 --> 21:58.260
And once you put anything in between this quotation, it's going to be string.

21:58.620 --> 21:59.900
So that is the reason.

21:59.900 --> 22:01.860
So make sure you just do that.

22:02.140 --> 22:05.060
And we also need to call this uh delete score function.

22:05.060 --> 22:07.540
And what this score function just gonna do.

22:07.580 --> 22:12.060
It's gonna delete the key or in which key we just saved our data.

22:12.060 --> 22:13.780
So in my case high score.

22:13.780 --> 22:15.300
So we just say deleting.

22:15.300 --> 22:19.140
And after that we just also updating in the UI saying zero.

22:19.180 --> 22:25.090
As you can see simply we just going over to that high score text this basically this high score And

22:25.090 --> 22:26.410
then accessing this text.

22:26.410 --> 22:28.610
And we're setting this text equal to zero.

22:28.650 --> 22:29.650
As you can see.

22:29.650 --> 22:31.250
So it's going to be update.

22:31.490 --> 22:37.330
And I want to check something like once I click right mouse button I just want to call this delete high

22:37.370 --> 22:38.250
score function.

22:38.250 --> 22:41.450
And this delete high score function is just going to do these things.

22:41.450 --> 22:45.290
So I'm going to call it over here inside this update function.

22:45.290 --> 22:46.250
And I'm going to check.

22:46.250 --> 22:48.410
So I'm going to check for some input.

22:48.450 --> 22:50.250
And I want to check over here.

22:50.250 --> 22:55.090
So I'm going to pass this input dot get mouse button down.

22:55.090 --> 22:57.810
And over here in brackets I'm going to pass one.

22:58.170 --> 23:03.290
One basically means the right mouse button means if we're clicking the right mouse button then what

23:03.290 --> 23:06.330
I'm going to do I'm going to call this delete high score function.

23:06.330 --> 23:12.090
And this delete high score function is just going to delete this data in which as a key we just store

23:12.130 --> 23:12.250
it.

23:12.250 --> 23:13.650
So in our case high score.

23:13.650 --> 23:20.970
So I'm going to call the high score delete delete high score or delete score once I click the right

23:21.010 --> 23:21.530
mouse button.

23:21.530 --> 23:23.050
So I'm going to call the function.

23:23.050 --> 23:24.370
And let's make first bucket.

23:24.410 --> 23:26.050
Let's close that off with semicolon.

23:26.050 --> 23:30.330
And we're going to press down Ctrl S to save our scroll to save our script.

23:30.330 --> 23:31.570
And let's move to unity.

23:31.570 --> 23:37.250
So whenever we're clicking the right mouse button then what we're doing we're just going or just calling

23:37.250 --> 23:38.890
the delete Highscore function.

23:38.890 --> 23:40.930
And what delete high score function is doing.

23:40.930 --> 23:42.690
It's just deleting our high score.

23:42.810 --> 23:48.410
And after that we just updating the UI which is high score with zero as you can see.

23:48.410 --> 23:52.650
So let's go to unity now and let's click on this play button in the top.

23:52.650 --> 23:58.650
You will see as soon as we're going to click right mouse button uh the saving data will be deleted.

23:58.650 --> 24:02.170
And after that we're just updating that high score with zero.

24:02.570 --> 24:07.170
Once we delete, uh, those uh, basically the saving data you will see.

24:07.850 --> 24:12.610
So just wait for it to come take damage and we can see it's deleted.

24:12.610 --> 24:14.210
Our player game object died.

24:14.370 --> 24:18.570
And if I just right click so the high score we can see 168.

24:18.570 --> 24:20.650
And as soon as we can right click.

24:20.970 --> 24:22.600
So if I just right click.

24:24.120 --> 24:25.840
So basically what we have done.

24:25.840 --> 24:27.400
So I'm going to get out of play mode.

24:28.000 --> 24:34.200
Uh over here as you can see if Game manager is uh instant dot is game active is false.

24:34.240 --> 24:40.560
Basically means once we, uh, once our player game object is died, then we just, uh, typing return

24:40.560 --> 24:44.640
and after return, whatever we're going to do, uh, it's not going to be saved.

24:45.960 --> 24:49.840
So what we're going to do, we're going to put this line of code by Ctrl X, and we're going to put

24:49.840 --> 24:53.440
it inside this control, uh, v by pasting it.

24:53.640 --> 25:00.200
So once we, uh, when we're doing these things, basically, uh, once our player game object destroy,

25:00.240 --> 25:03.600
then we just, uh, and we also checking, uh, sorry.

25:04.640 --> 25:09.760
Uh, uh, I'm going to put a over here, so I'm going to put in uh, top.

25:09.760 --> 25:15.280
So basically just put this line of code in top of your update function because after return we don't

25:15.280 --> 25:16.800
know it's not going to be work.

25:16.800 --> 25:20.350
So that's why we just put it, uh, before this thing.

25:20.670 --> 25:23.470
So I'm going to press down Ctrl S to save my script.

25:24.910 --> 25:27.110
And let's press down Ctrl s.

25:27.150 --> 25:28.470
Let's move to unity.

25:28.910 --> 25:34.510
So whenever we're going to click right mouse button by now it should be deleted because we're just putting

25:34.510 --> 25:38.950
that line of code before this before our player game object dies.

25:38.990 --> 25:43.550
And we do know after return whatever we're going to do it's not going to be executed.

25:43.550 --> 25:50.670
So that's why we just put that line of code before return or that game manager instance, uh, line

25:50.710 --> 25:51.230
of code.

25:51.790 --> 25:55.510
So just wait for to compile and we're going to able to see by now.

25:55.510 --> 26:00.710
So let's click on this play button in the top and let's have a look.

26:05.390 --> 26:10.310
And let's take damage from that enemy game object which is our skeleton.

26:12.710 --> 26:15.710
So let's take damage one two.

26:15.750 --> 26:18.230
And we can see the high score is 168.

26:18.230 --> 26:19.550
And if I just right click.

26:19.590 --> 26:24.430
As you can see, as soon as we right click the high score, just set it to zero.

26:24.430 --> 26:27.630
And we just deleted the saving data as well.

26:27.630 --> 26:29.470
And we just update in the UI.

26:29.470 --> 26:34.230
So basically what we're doing we're just going over to this high score then accessing this text.

26:34.270 --> 26:36.430
Once we deleting our score.

26:37.270 --> 26:41.510
And we're setting this text equal to over here as you can see zero.

26:41.510 --> 26:45.270
So that's why in the UI this also gets updated with zero.

26:45.270 --> 26:46.790
So basically that is the thing.

26:46.830 --> 26:48.590
And I'm gonna get out of play mode.

26:48.630 --> 26:54.590
I hope you get the idea that how you can show up the high score that you made, the current score,

26:54.590 --> 26:56.830
you just want to set as a new high score.

26:56.830 --> 26:57.950
So you can do that.

26:57.950 --> 27:02.630
So you can use Playerprefs in order to, uh, save specific data.

27:02.630 --> 27:09.230
And if you just want to save multiple datas, then you can, uh, check that out on YouTube.

27:09.390 --> 27:13.030
Uh, so you can just go do that if you just want to do it.

27:13.030 --> 27:18.070
So I'm going to press Ctrl s on my keyboard to save my project.
