WEBVTT

00:03.390 --> 00:03.960
Hello guys.

00:03.960 --> 00:05.040
Welcome to the video.

00:05.040 --> 00:10.980
In this one I want to show you how to update level buttons so they have a relevant information about

00:10.980 --> 00:11.820
levels.

00:12.270 --> 00:13.470
As example.

00:13.650 --> 00:15.180
Let me just quickly explain.

00:15.180 --> 00:18.750
So at the moment we have just level one, level two level three.

00:18.750 --> 00:21.780
And what I want to do here is to display level name.

00:21.780 --> 00:26.700
Then I want to show the best time on the level, like how many seconds it took you to complete the level.

00:26.700 --> 00:31.950
And then over here I want to show you how many total fruits there are on the level, and also how many

00:31.950 --> 00:36.840
fruits you collected from this level so player can see how many fruits he missed, and then he can just

00:36.840 --> 00:39.000
go there again and collect all of the fruits.

00:39.000 --> 00:45.540
Okay, also, if we did not unlock the level, if he did not play this level before, then we're going

00:45.540 --> 00:47.490
to show zero out of question mark.

00:47.490 --> 00:49.830
So we don't know how many fruits on the level there.

00:49.860 --> 00:50.250
All right.

00:50.250 --> 00:51.150
That's what we're going to do.

00:54.050 --> 00:58.670
Uh, let's go to the skin selection UI.

00:58.700 --> 01:00.560
I mean, level selection UI.

01:00.920 --> 01:06.980
I'm going to take prefab UI level button, and I'm going to work on this button.

01:06.980 --> 01:10.700
And then I'm going to just overwrite the prefab.

01:10.760 --> 01:11.360
Okay.

01:11.360 --> 01:13.790
So first I want to change the color.

01:13.790 --> 01:16.880
Let's go to the button component.

01:17.970 --> 01:21.270
Normal color will be something like dark blue.

01:21.300 --> 01:22.260
I guess.

01:24.810 --> 01:26.460
Yeah, something like this.

01:26.700 --> 01:29.520
And then highlighted color will be light blue.

01:30.800 --> 01:31.670
Is it blue?

01:32.270 --> 01:32.720
I'm not sure.

01:32.750 --> 01:34.160
Guys, I'm color blind.

01:35.340 --> 01:36.000
Okay.

01:36.000 --> 01:39.990
Now, when you put in your mouse over the button, it's going to look like this.

01:41.720 --> 01:42.890
I think it's pretty.

01:42.920 --> 01:44.960
Maybe put more work on the colors.

01:50.920 --> 01:51.730
Yes.

01:51.730 --> 01:52.540
Like that.

01:56.270 --> 02:02.960
Now I'm going to take the text and let me change font to the Minecraft SDF.

02:02.960 --> 02:05.060
Let's make it white.

02:06.200 --> 02:09.650
And let's make the text box itself slimmer.

02:10.560 --> 02:11.460
Like this.

02:12.020 --> 02:14.570
I'm going to just maybe move it down a little bit.

02:16.800 --> 02:19.170
And let's say this says level one.

02:19.290 --> 02:22.920
Now let's change the name to level number.

02:24.300 --> 02:27.630
Next and we want to duplicate this.

02:28.700 --> 02:30.260
Let's move it below.

02:30.530 --> 02:33.590
Let's change font size to 18.

02:34.890 --> 02:37.470
And this one will be best time.

02:37.470 --> 02:39.690
Let's say 99 seconds.

02:39.690 --> 02:40.500
We've got.

02:40.680 --> 02:41.400
Okay.

02:41.960 --> 02:48.380
And I think we can do alignment to the left and just move it a little bit to the right.

02:48.380 --> 02:53.870
Let me just attach it to the left side over here, and I'm going to move it to the right like that.

02:56.110 --> 02:56.500
Yeah.

02:56.500 --> 02:57.460
This should be good.

02:57.490 --> 03:01.360
Now let's change this to best time text.

03:01.780 --> 03:03.580
And also we want to duplicate it.

03:03.700 --> 03:05.770
Actually I just want to move it a little bit here.

03:05.770 --> 03:06.340
Down.

03:06.370 --> 03:06.970
Okay.

03:06.970 --> 03:08.290
Now I'm going to duplicate it.

03:08.290 --> 03:10.930
This one going to be route text.

03:11.650 --> 03:15.580
Now let's move it down and let's say this one will be fruits.

03:16.610 --> 03:21.200
Um, zero out of five like that.

03:22.450 --> 03:24.190
Now for the text over here.

03:24.190 --> 03:25.090
I mean, for the fruits.

03:25.090 --> 03:26.650
I want to add an icon.

03:26.830 --> 03:31.300
So I'm going to go ahead and make UI image.

03:32.250 --> 03:35.070
Let's name it as a fruit icon.

03:35.430 --> 03:36.720
Then we're going to open image.

03:36.720 --> 03:42.960
Go to graphics, find an apple and let's put Apple over here.

03:43.380 --> 03:44.130
Nice.

03:44.160 --> 03:45.960
Now I think the size should be smaller.

03:45.960 --> 03:47.970
I'm going to try 60 by 60.

03:48.690 --> 03:49.860
That looks good to me.

03:51.040 --> 03:55.480
Let's just attach it to the center and move it to the right a little bit.

03:57.220 --> 03:58.750
Yeah, like that should be good.

03:59.680 --> 04:00.820
And now we're gonna.

04:03.090 --> 04:04.260
Go to the script.

04:04.260 --> 04:06.540
Make a variable for those two texts.

04:07.250 --> 04:11.720
So I'm going to do serialize field private text mesh Pro.

04:12.640 --> 04:13.300
Guy.

04:14.050 --> 04:15.100
Uh, timer.

04:15.900 --> 04:17.850
Best time text.

04:17.850 --> 04:23.640
And we're going to neutralize field private text, mesh progue routes text.

04:23.640 --> 04:24.450
All right.

04:24.450 --> 04:30.690
Now we need to, uh, have information saved so we can pull this information, load it and give it to

04:30.690 --> 04:31.440
the button.

04:31.440 --> 04:35.370
As of now, we don't have this information, so I'm just going to go back to unity.

04:36.820 --> 04:41.440
I'm going to assign text over here and throw text over here.

04:41.440 --> 04:45.670
Then I want to do apply overrides and I'll disable this button.

04:45.670 --> 04:47.920
Now let's go ahead to the Visual Studio.

04:47.920 --> 04:49.960
And we need to save this information.

04:49.960 --> 04:51.160
We need to know it.

04:51.160 --> 04:52.840
So on the game manager.

04:54.740 --> 04:55.370
Uh.

04:56.470 --> 04:57.760
Somewhere here.

04:57.760 --> 04:59.200
I'm going to make a method.

05:00.630 --> 05:01.500
Private void.

05:01.500 --> 05:03.840
Save best time.

05:05.440 --> 05:07.780
And we're going to just do something simple here.

05:07.780 --> 05:08.950
Playerprefs.

05:10.370 --> 05:11.000
Set.

05:11.000 --> 05:11.690
Float.

05:12.490 --> 05:13.390
Level.

05:13.390 --> 05:15.970
Plus level.

05:17.770 --> 05:22.960
Plus current level index plus best time.

05:22.960 --> 05:27.550
And we're going to give it value of a level timer just like that.

05:28.600 --> 05:30.100
Now let's call it here.

05:30.100 --> 05:32.800
Save best time and this will save the time.

05:32.800 --> 05:34.660
So we don't need to check it, I know it.

05:34.960 --> 05:36.610
Uh, we're just going to use it later on.

05:36.610 --> 05:38.170
Let's make another method.

05:38.500 --> 05:41.050
Private void save.

05:41.550 --> 05:42.960
Routes info.

05:43.290 --> 05:48.840
And before we do anything here, let's go to the collect fruit info over here.

05:48.840 --> 05:52.140
And we want to save total amount of fruits on the level.

05:52.140 --> 05:53.970
So we're going to do player pref.

05:54.960 --> 05:57.450
Set int uh.

05:57.450 --> 05:58.230
Level.

05:58.230 --> 05:59.070
Sorry.

05:59.430 --> 06:08.910
Level plus uh current level index plus total fruits and value will be total fruits.

06:08.910 --> 06:09.900
So this will save it.

06:09.900 --> 06:11.970
And we can use it on the button later on.

06:11.970 --> 06:15.030
Now we're going to go down back to this method.

06:15.030 --> 06:17.250
And over here we're going to do player.

06:18.300 --> 06:20.220
Ref set.

06:20.220 --> 06:23.400
End of level.

06:24.390 --> 06:30.660
Plus, uh, current level index plus routes collected.

06:30.870 --> 06:34.650
Now, this will save information about how many fruits we collected on the level.

06:34.650 --> 06:36.240
And I kind of like it.

06:36.330 --> 06:37.650
Uh, fruit collected.

06:37.650 --> 06:39.870
But we need to do something here.

06:39.870 --> 06:42.360
Imagine you collected four fruits on the level.

06:42.360 --> 06:45.360
You save the info, then you run in the same level again.

06:45.360 --> 06:47.040
And you did not collect four fruits.

06:47.040 --> 06:48.510
You collected three.

06:48.510 --> 06:53.040
And if you do not do anything in this method, then information will be overwritten and you'll have

06:53.040 --> 06:54.360
three instead of four.

06:54.360 --> 06:55.650
That's not what I want.

06:55.650 --> 06:56.970
So we're going to do this.

06:56.970 --> 06:58.500
We're going to make int.

06:59.690 --> 07:03.680
Roads connected before equals to playerprefs.

07:03.710 --> 07:05.480
Get int off.

07:05.480 --> 07:11.660
And we're going to take this name over here and paste it in here like that.

07:11.660 --> 07:17.570
And then we're going to check if fruits collected before is less than fruits collected.

07:17.810 --> 07:21.950
Then we're going to set this integer over here.

07:22.400 --> 07:27.920
So just like that we're getting the info from the previous session or from previous save.

07:27.920 --> 07:33.470
And if it's less than we collect it now then we override it and we save information again.

07:33.710 --> 07:34.700
Very cool.

07:34.700 --> 07:40.430
Now for the total fruits collected, because we want to have some sort of a bank which we can use as

07:40.430 --> 07:42.590
a currency to buy skins in the menu.

07:42.650 --> 07:47.510
I'm going to do int total fruits in bank.

07:47.510 --> 07:51.830
Why not playerprefs get int of?

07:54.560 --> 07:59.090
Total fruits collected or actually I when I have a different name for this.

07:59.090 --> 08:03.230
So it's at least a little bit dis dis dis.

08:03.560 --> 08:07.370
I mean it's a little bit different from another one from this one.

08:07.370 --> 08:10.250
So I couldn't say distinguished.

08:10.250 --> 08:11.120
And now I did it.

08:11.120 --> 08:11.930
Yes.

08:11.930 --> 08:12.290
Okay.

08:12.290 --> 08:13.940
So I'm going to do total fruits amount.

08:13.940 --> 08:15.710
And here we're just getting the value.

08:15.710 --> 08:22.460
And then we're going to do Playerprefs set int of total fruits amount.

08:22.460 --> 08:24.110
Just so I won't make any mistakes.

08:24.110 --> 08:26.960
I'm going to copy it from here and paste it in here.

08:27.110 --> 08:33.890
And then I'm going to do total fruits in bank plus fruits collected in this way.

08:33.890 --> 08:39.800
Whenever we save the level info, we're going to add fruits that we collected to the total bank we have.

08:39.800 --> 08:41.030
And we can use it later on.

08:41.030 --> 08:44.180
And I think that's all that we need.

08:44.180 --> 08:45.200
Let me think about it.

08:45.230 --> 08:48.920
We save the fruits collected on the level so we can display it on a button.

08:48.920 --> 08:53.510
We did save total amount of fruits on the level, and we did save fruits that we collected.

08:53.510 --> 08:54.680
So we can use them later on.

08:54.680 --> 08:55.820
So this should be good.

08:57.580 --> 09:00.790
Let's go here and call save route info.

09:01.060 --> 09:02.200
This is nice.

09:03.220 --> 09:05.740
And now we need to go to UI level button.

09:05.740 --> 09:10.480
And over here we need to give info to these two texts over here.

09:10.570 --> 09:17.290
So first of all, let's make a private string because I just want to return text timer info text.

09:17.290 --> 09:21.520
And over here we're going to need the value of a timer we saved.

09:21.640 --> 09:23.320
I'm going to go to Game Manager.

09:24.190 --> 09:30.280
I'm going to copy this and I'm going to go to level button, paste the scene and we're going to do float.

09:31.370 --> 09:33.950
Timer value equals to playerprefs.

09:34.010 --> 09:36.140
Get float.

09:38.480 --> 09:44.990
With a level index, and we don't have a default value here yet, but I want to give it a value of 99.

09:44.990 --> 09:48.410
So if we don't have any best time, we're just going to put 99 there.

09:48.410 --> 09:51.230
Let player know that this level was not completed yet.

09:51.230 --> 09:52.730
Now we're going to return.

09:53.810 --> 10:00.320
Best time columns, space plus timer value two string.

10:00.320 --> 10:03.830
And we want to format it the same way as before zero zero.

10:04.280 --> 10:05.180
And that's it.

10:05.180 --> 10:12.080
Now on a setup button we're going to do best timer text dot text equals to timer info text.

10:12.170 --> 10:12.890
Cool.

10:12.890 --> 10:15.230
Now we need to do the same for the fruits we have.

10:15.230 --> 10:20.450
It's going to be a little bit more complicated, but actually very simple.

10:20.450 --> 10:21.230
Overall.

10:21.230 --> 10:23.690
Let's make a private string.

10:25.390 --> 10:26.260
Routes.

10:26.650 --> 10:27.430
Info.

10:27.430 --> 10:28.270
Text.

10:28.820 --> 10:29.690
And over here.

10:29.690 --> 10:31.460
We need to go to game manager.

10:32.030 --> 10:35.330
First of all, I want to copy this.

10:35.330 --> 10:36.740
Let me copy this.

10:37.100 --> 10:38.480
I mean this line of code.

10:39.840 --> 10:40.350
Over here.

10:40.350 --> 10:45.780
We're going to do int total fruits on level equals to.

10:47.060 --> 10:50.060
This and we're going to use level index.

10:51.460 --> 10:53.530
And we don't want to have any default value.

10:53.530 --> 10:57.820
Actually, we want to have a default value of a zero because I want to use it later on.

10:58.120 --> 10:59.530
I'm going to show you how to.

11:00.010 --> 11:02.830
And over here it's supposed to be get int.

11:03.550 --> 11:06.070
And no parentheses over here.

11:06.070 --> 11:06.760
Okay.

11:07.360 --> 11:09.490
Maybe let's rename it to Total Fruits.

11:09.490 --> 11:10.480
It's a bit better.

11:11.770 --> 11:16.270
Now look, this will return us info if we did save a new value before.

11:16.270 --> 11:19.480
But if we did not save anything, it's going to show us zero.

11:19.480 --> 11:21.430
But I don't want to show zero.

11:21.430 --> 11:22.930
I want to show question mark.

11:22.930 --> 11:24.580
I want it to be intriguing.

11:24.580 --> 11:30.130
So I'm going to make a local variable of a string, total fruits text.

11:30.220 --> 11:34.300
And it will be decided by the quick if statement.

11:34.300 --> 11:37.000
Over here we're going to do this equals two.

11:37.000 --> 11:40.390
And then we're going to ask total fruits is equals to zero.

11:41.330 --> 11:46.310
If yes, then total fruits text will be equal to question mark.

11:46.370 --> 11:50.600
If no, then it's going to be equals to total fruits two string.

11:51.050 --> 11:51.950
Very nice.

11:51.950 --> 11:53.300
So this is decided.

11:53.300 --> 11:56.300
Now we need info about fruits collected on the level.

11:56.660 --> 11:58.370
I'm going to go to Game manager.

11:59.040 --> 12:01.770
And over here we have this.

12:03.800 --> 12:05.150
Fruits collected.

12:05.840 --> 12:08.810
So I'm going to I can just take this one over here.

12:09.420 --> 12:10.650
Let's take it.

12:11.320 --> 12:12.100
Go back.

12:12.990 --> 12:13.740
Paste it in.

12:13.740 --> 12:18.750
And over here we're going to do int fruits collected equals to this.

12:18.750 --> 12:23.550
And instead of current level index it will be level index.

12:24.660 --> 12:26.430
And then this one going to return me.

12:26.430 --> 12:27.750
Let's do return.

12:27.750 --> 12:29.010
Return.

12:29.370 --> 12:29.820
Um.

12:30.930 --> 12:34.470
Rhodes columns, plus.

12:35.320 --> 12:36.640
Jackfruits collected.

12:37.240 --> 12:39.820
Plus SpaceX slash SpaceX.

12:40.180 --> 12:41.920
Plus total fruits.

12:41.920 --> 12:42.670
Text.

12:43.170 --> 12:45.060
And I forgot semicolons over here.

12:45.780 --> 12:46.500
Cool.

12:46.500 --> 12:47.820
Super cool.

12:47.850 --> 12:51.690
Now let's go to the setup button and do fruits text.

12:51.690 --> 12:55.620
The text equals to fruits info text.

12:56.890 --> 12:58.390
On this supposed to be good?

12:58.420 --> 13:04.090
Actually, I did check it twice because I was recording this video and I forgot to press record button,

13:04.090 --> 13:06.820
which sometimes happens to everyone.

13:07.150 --> 13:08.020
I hope.

13:08.570 --> 13:10.280
Now I'm going to go to.

13:11.540 --> 13:11.870
Yeah.

13:11.870 --> 13:15.320
And also I just did it once to make a prototype and see how it works.

13:15.320 --> 13:16.880
But let's check it.

13:17.090 --> 13:19.460
Let's do clear all playerprefs.

13:20.640 --> 13:21.900
Going to go to play mode.

13:22.830 --> 13:27.930
So by default it shows me 99 zero out of question mark going to jump on the level.

13:30.320 --> 13:31.730
Can I collect some?

13:32.210 --> 13:36.680
I'm going to go to the next one, complete the second one, but I'm not going to complete the third

13:36.680 --> 13:37.130
one.

13:38.200 --> 13:39.880
Because it has no fruits anyway.

13:40.900 --> 13:42.580
Let's go out of a play mode.

13:42.850 --> 13:44.650
Let's go to play mode again.

13:46.230 --> 13:51.630
And over here we have new level unlocked which has 99 zero to the question mark here.

13:51.630 --> 13:55.530
Best time was zero for fruits three out of six here.

13:55.530 --> 13:56.610
It's a bit different.

13:56.970 --> 13:58.320
Uh, four out of five.

13:58.320 --> 13:59.790
And best time is four.

13:59.820 --> 14:00.360
What to do?

14:00.360 --> 14:01.350
Let me just double check.

14:01.350 --> 14:02.160
It's not a bug.

14:02.160 --> 14:05.910
I'm going to just wait for more time here.

14:06.600 --> 14:07.710
It's going to be best time.

14:07.710 --> 14:08.580
Oh, this is good.

14:08.580 --> 14:13.200
I'm checking this because now I'm going to overwrite the info and it's not going to be the best time.

14:13.200 --> 14:15.150
It's just going to be the last time I.

14:15.150 --> 14:16.110
It took me.

14:16.410 --> 14:17.010
Yeah.

14:17.720 --> 14:18.680
Seven seconds.

14:18.680 --> 14:19.460
Oh my God.

14:19.460 --> 14:20.930
Okay, let's fix it.

14:21.950 --> 14:23.330
Let's go to game manager.

14:24.090 --> 14:25.590
Uh, over here on the save.

14:25.590 --> 14:26.310
Best time.

14:26.310 --> 14:28.260
We need to do load.

14:28.260 --> 14:32.820
Last time equals to playerprefs get float.

14:32.820 --> 14:33.780
And I'm a bit lazy.

14:33.780 --> 14:36.270
I'm going to just copy it from here.

14:36.570 --> 14:38.100
Paste it in here.

14:39.760 --> 14:41.830
And default one can be 99.

14:42.400 --> 14:44.050
And then I'm going to do this.

14:44.050 --> 14:48.940
If level timer is less than last time, then we're going to save this.

14:49.690 --> 14:50.380
Right.

14:51.370 --> 14:52.960
They should be better.

14:52.960 --> 14:54.640
Let me save the script.

14:54.670 --> 14:58.150
Now we know that on a second level, it took me seven seconds.

14:58.150 --> 15:01.360
And now I'm going to try to run this as fast as possible.

15:06.220 --> 15:06.880
Seven.

15:06.880 --> 15:07.780
Let's go.

15:11.050 --> 15:15.190
And it was, uh, four seconds when I entered the finish line.

15:15.460 --> 15:17.080
Let me see it now.

15:18.750 --> 15:20.250
And it has for now.

15:20.250 --> 15:21.300
Let me just double check.

15:21.300 --> 15:22.590
I'm going to take longer.

15:22.590 --> 15:25.950
And if I'm not wrong, it's not supposed to save any time there.

15:35.870 --> 15:36.530
All right.

15:36.530 --> 15:38.780
Zero for fruits, six out of six.

15:38.780 --> 15:39.770
I love it, man.

15:39.770 --> 15:40.850
This is so good.

15:40.940 --> 15:43.640
Now this is it.

15:43.640 --> 15:46.880
Let's save the project and let's go to the next video.
