WEBVTT

00:00.080 --> 00:00.590
Hello guys.

00:00.590 --> 00:01.580
Welcome to the video.

00:01.580 --> 00:04.280
In this one we're going to work on a level selection UI.

00:04.340 --> 00:05.540
Going to be pretty simple to do.

00:05.570 --> 00:08.810
We just need to use a couple of new components that we didn't see before.

00:08.810 --> 00:12.140
And then I have a way of automating the level system.

00:12.140 --> 00:13.460
So we can just create levels.

00:13.460 --> 00:16.070
And the rest of the things will be done by the script we have.

00:16.070 --> 00:18.140
So let's open level selection UI.

00:18.710 --> 00:24.410
And first, before we make any levels, we need some sort of an area where we can place buttons that

00:24.410 --> 00:26.270
will help us to choose level.

00:26.270 --> 00:28.160
So we're going to click right button.

00:29.160 --> 00:31.740
And make UI scroll view.

00:32.100 --> 00:37.380
So scroll view allows you to scroll window like horizontally and vertically.

00:37.410 --> 00:39.750
First of all, let's make it bigger.

00:40.830 --> 00:43.800
Maybe something like this will work for us.

00:43.800 --> 00:44.400
Yeah.

00:44.400 --> 00:48.660
Now we want to remove this, uh, scroll bar here and here.

00:48.660 --> 00:50.340
We don't need it because it's going to work anyway.

00:50.340 --> 00:50.640
Just.

00:50.640 --> 00:53.910
We don't want to see that scroll bars on the side.

00:53.910 --> 00:56.040
Now, how it's going to work.

00:56.040 --> 01:03.300
Well, we can arrange buttons inside of this, uh, content window manually with our hands, but that

01:03.300 --> 01:05.190
would take a lot of time to do.

01:05.190 --> 01:06.150
So better.

01:06.150 --> 01:09.630
We're going to use component to arrange buttons automatically.

01:09.630 --> 01:12.240
Then I'm going to explain how the scroll view works.

01:12.240 --> 01:12.780
Okay.

01:12.780 --> 01:13.650
Let's just see it.

01:13.650 --> 01:18.210
First I'm going to make UI uh button here.

01:19.140 --> 01:23.610
And let's just duplicate this button a bunch of times, like really a lot.

01:23.610 --> 01:28.380
So now we have 22 buttons and they all at one place.

01:28.380 --> 01:33.720
And it would be a really big headache for us to place them with our hands in the order that we want.

01:33.720 --> 01:41.670
Instead, we can select Content Object and we can add a grid layout group.

01:42.030 --> 01:47.880
Now these buttons will be arranged automatically and more to that, this component can change size of

01:47.880 --> 01:49.650
the object buttons as well.

01:49.650 --> 01:56.280
So for example, I want it to be 250 uh, on the X and 100, and the Y is fine.

01:56.280 --> 01:58.950
Also, I would like to have a bit of a space in between buttons.

01:58.950 --> 02:01.860
So I'm going to put spacing on the x 25.

02:02.980 --> 02:03.790
Yeah, this is good.

02:03.790 --> 02:04.510
And on the way.

02:04.540 --> 02:05.590
Maybe 15.

02:06.580 --> 02:07.630
Nice.

02:07.630 --> 02:09.460
And let's keep child alignment.

02:09.460 --> 02:10.690
Upper left.

02:10.960 --> 02:12.610
Uh, start corner, upper left.

02:12.610 --> 02:14.740
So basically, we don't need to change anything here.

02:14.740 --> 02:16.210
Now, look, this looking fine.

02:16.210 --> 02:20.920
I like it, but I don't like that we don't have any spacing on the left and on the top.

02:20.920 --> 02:28.120
To fix that, we can go to the viewport and let's adjust the size of a viewport.

02:28.120 --> 02:33.430
Let's press T and maybe scroll it down like that.

02:33.430 --> 02:35.320
And let's do alignment in the center.

02:35.320 --> 02:36.910
I'm gonna align it to the center.

02:36.910 --> 02:39.400
And I'm going to hold Shift and Alt here.

02:39.400 --> 02:44.440
Click this and then let's just reduce the size of a viewport.

02:45.510 --> 02:46.770
To something like.

02:48.260 --> 02:48.950
This.

02:51.250 --> 02:51.430
Yeah.

02:51.460 --> 02:52.240
Can you see that?

02:52.240 --> 02:57.280
So now it will not be attached to the borders and it looks much better and prettier.

02:57.280 --> 02:58.300
Very nice.

02:59.600 --> 03:01.460
Now what else we can do here?

03:03.780 --> 03:06.030
I don't like how it looks now.

03:06.060 --> 03:11.130
We have six rows for buttons, but there is lots of space on the right, so maybe a bit more spacing

03:11.130 --> 03:11.910
on the X.

03:17.070 --> 03:20.130
Um, let's try to add padding from the left.

03:21.010 --> 03:24.910
Something like this will do, I guess 70.

03:25.120 --> 03:27.490
Maybe we can arrange everything with bedding.

03:27.490 --> 03:29.140
I think that would be a good idea.

03:29.140 --> 03:31.270
Let's stretch it back how it was.

03:31.270 --> 03:35.140
And let's take the content and just add padding on the top.

03:36.370 --> 03:37.270
20 is good.

03:37.270 --> 03:38.860
20 from the bottom.

03:39.070 --> 03:39.700
Let's see.

03:39.700 --> 03:41.680
Maybe more padding on the left.

03:42.330 --> 03:43.410
Like that.

03:44.380 --> 03:45.310
100.

03:45.960 --> 03:49.140
It seems like a hundred is 110.

03:49.170 --> 03:50.640
Yeah, 110 seems like.

03:50.640 --> 03:52.530
Okay, so this is good.

03:52.530 --> 03:55.770
Now we have buttons that are arranged with a grid layout group.

03:55.770 --> 04:00.660
And also these buttons can be scrolled because all of this is a part of a scroll view.

04:00.660 --> 04:02.880
Now let's go ahead to play mode and see.

04:03.740 --> 04:05.060
How does it work right now?

04:05.060 --> 04:07.220
Because we need to fix a couple of things here.

04:07.220 --> 04:10.490
First of all, we can scroll down.

04:12.040 --> 04:13.570
Uh, we need more buttons, I guess.

04:13.600 --> 04:15.070
Let's add more.

04:16.680 --> 04:18.960
So let's say we have this many levels.

04:18.960 --> 04:26.730
And when we go to play mode and try to scroll down, you can see it returns back to the first, uh,

04:26.730 --> 04:27.870
buttons we have.

04:27.870 --> 04:29.370
I cannot scroll down.

04:29.370 --> 04:37.890
So that happens because scroll view and the scroll availability, let's say is determined by the size

04:37.890 --> 04:39.960
of the content window over here.

04:39.960 --> 04:44.550
We basically need to stretch it like that, and then it will allow us to scroll down more.

04:44.550 --> 04:48.270
But still you cannot scroll all the way down.

04:48.270 --> 04:53.670
That happens because again, this content window is not the size of all buttons we have.

04:53.670 --> 05:01.050
We basically would have to do something like this, so it will allow us to scroll down more.

05:02.480 --> 05:09.050
Now you can see I can scroll down, but we cannot fix it manually every time we add or delete buttons.

05:09.140 --> 05:12.920
To overcome that, we can go here and click Add Component.

05:13.100 --> 05:16.130
And then we're going to choose Content Size Filter.

05:16.520 --> 05:20.210
And on the vertical we need to choose Mean size.

05:21.370 --> 05:27.340
Because of that, this window will adjust itself according to the amount of elements it has.

05:27.370 --> 05:29.740
If I'm deleting half of this.

05:31.990 --> 05:33.610
Then it's going to have this size.

05:34.830 --> 05:36.150
If I add more.

05:37.140 --> 05:43.020
You can see it is increasing the size of itself automatically, which is really convenient for us.

05:44.130 --> 05:44.910
Very nice.

05:44.910 --> 05:47.520
Now let's talk about the scroll view itself.

05:47.520 --> 05:52.590
As of now it behaves in a certain way and we can adjust it to make it work for us.

05:52.590 --> 05:55.620
First of all, it can be scrolled horizontally as well.

05:55.620 --> 05:56.730
That's not what we want.

05:56.730 --> 06:00.270
So we would have to disable horizontal here.

06:00.270 --> 06:03.420
Now you cannot scroll horizontally, only vertically.

06:03.420 --> 06:04.380
That is good.

06:04.380 --> 06:05.580
Now something else.

06:05.580 --> 06:07.770
If you try to scroll down it's fine.

06:07.770 --> 06:13.350
But if you try to scroll up, you can see it bounces back to the position it had.

06:13.350 --> 06:15.450
And I like how it works, so I'm going to keep it at that.

06:15.450 --> 06:20.370
I just want to tell you that this parameter is controlled by the elasticity over here.

06:20.370 --> 06:25.020
And if you increase it, it's going to look a bit weird because it's going to just scroll down and then

06:25.020 --> 06:27.060
it's going to bounce back but much slower.

06:27.060 --> 06:31.260
So I prefer to keep this at low like 0.1 is fine.

06:31.260 --> 06:36.390
Then we have inertia which basically keeps the movement after you stop scrolling.

06:36.390 --> 06:41.280
So if I try to scroll a bit, you can see there is a bit of a movement even when I stop.

06:41.280 --> 06:49.440
And if you increase this value like that and you just scroll a little bit, it's going to scroll it

06:49.740 --> 06:52.170
automatically, which I don't really like.

06:52.170 --> 06:54.330
So I'm going to keep this at low value as well.

06:55.790 --> 07:00.500
And now scroll sensitivity affects the Will button on your mouse.

07:00.500 --> 07:05.540
So as of now, if I try to scroll it with my wheel button, it's really difficult to do.

07:05.540 --> 07:11.390
But if you increase this value to 30, for example, then it becomes much easier.

07:12.430 --> 07:13.240
All right.

07:13.240 --> 07:15.070
So I can select these parameters.

07:15.070 --> 07:16.150
And I'm going to keep them.

07:16.150 --> 07:22.750
So let me just copy component go out of a play mode and then paste component values.

07:22.960 --> 07:23.470
Great.

07:23.470 --> 07:24.970
So now we know how it works.

07:24.970 --> 07:28.210
Before we go any further let's delete the extra buttons here.

07:28.210 --> 07:33.460
And now we need to make a couple of levels so we can go to some levels with these buttons.

07:33.460 --> 07:33.640
Right.

07:33.640 --> 07:34.960
Because now we just have one level.

07:34.960 --> 07:37.150
So there is no point of having multiple buttons.

07:37.150 --> 07:39.340
So how are we going to make a couple of levels.

07:39.340 --> 07:46.840
First of all, let's take this sample scene and let's change the name of this scene to uh level underscore.

07:46.840 --> 07:49.690
And let's make it maybe as three okay.

07:50.560 --> 07:54.670
Now I'm going to duplicate this and let's do duplicate.

07:54.700 --> 07:56.320
It's not going to be level one.

07:56.320 --> 07:59.440
And we need to duplicate it one more time and do level two.

07:59.470 --> 08:01.360
Now I'm going to go inside of this scene.

08:01.360 --> 08:03.250
And here let's save the changes.

08:03.250 --> 08:06.310
And over here I'm going to somehow change the level.

08:06.310 --> 08:08.740
So it's easier for me to recognize the difference.

08:08.740 --> 08:11.260
And also maybe it will serve some purpose.

08:11.260 --> 08:16.600
For example, in this level I just want to let player know that he can move left and right and he can

08:16.600 --> 08:17.050
jump.

08:17.050 --> 08:23.440
That's why I'm going to make something very simple, where he has just to go left and right and collect

08:23.440 --> 08:23.980
some fruits.

08:23.980 --> 08:26.560
That's the only thing I want him to do in this level.

08:26.560 --> 08:30.970
So I'm going to take the wooden platform and do like that.

08:31.480 --> 08:31.840
All right.

08:31.840 --> 08:36.310
So I tried to make something interesting, but ended up with a very simple level over here.

08:36.550 --> 08:38.290
And that's going to be just the first level.

08:38.290 --> 08:44.650
I just want to teach player that he can jump, and that's all he's going to do in this, um, level.

08:45.470 --> 08:48.170
Now let me make a second level real quick.

08:48.200 --> 08:50.120
I'm going to go to level two.

08:50.210 --> 08:51.620
Let me save the changes.

08:51.620 --> 08:55.910
And in this scene, for example, I want player to learn that he can do double jump.

08:59.810 --> 09:00.440
Yeah.

09:00.440 --> 09:01.340
Totally possible.

09:01.340 --> 09:01.820
Okay.

09:05.480 --> 09:06.620
So this is the level two.

09:06.620 --> 09:08.420
And we have level three as well.

09:08.420 --> 09:09.140
Very nice.

09:09.140 --> 09:09.860
Level one.

09:09.860 --> 09:11.660
Level two level three.

09:11.660 --> 09:13.520
Now let's go back to main menu.

09:13.520 --> 09:16.850
And over here we have a goal a very simple goal.

09:16.850 --> 09:20.210
This button can load the scene that we want.

09:20.210 --> 09:27.350
It just need to know the name of the scene or the index of the scene and let me go back.

09:28.440 --> 09:29.850
To this viewport.

09:29.850 --> 09:32.010
There is a content and there is a button.

09:32.580 --> 09:35.580
So this is the button that is responsible for opening the level.

09:35.580 --> 09:40.080
And we want to create button for each level we have in the build settings.

09:40.080 --> 09:44.400
So first of all let's go to File Build Profile Sin list.

09:44.400 --> 09:47.070
And over here we have only main menu level three.

09:47.070 --> 09:48.210
And the end.

09:48.210 --> 09:49.530
We need to take level one.

09:49.530 --> 09:50.340
Drag it here.

09:50.340 --> 09:52.560
And we need to take level two and drag it here.

09:52.560 --> 09:58.740
Now all of the scenes are in the scene list and we can see that each scene has an index.

09:58.740 --> 10:00.570
This one is zero for the main menu.

10:00.570 --> 10:06.000
Then level one has one, level two has two, level three is three and the end has the last one.

10:06.000 --> 10:10.080
And we can utilize this index to open the scene that we want.

10:10.080 --> 10:14.790
Or we can take the name of the scene and open the scene that we want.

10:14.790 --> 10:18.360
Or we can take both parameters and make it work for us.

10:18.360 --> 10:25.800
We can take the name to open the scene and index will allow us to make this process automatic.

10:26.420 --> 10:29.060
First let's add component on a button.

10:29.240 --> 10:32.360
It's going to be UI level button.

10:34.020 --> 10:35.610
Let me find that script.

10:35.640 --> 10:37.740
UI level button over here.

10:37.740 --> 10:40.710
I'm going to make variable public just so we know that it works.

10:40.710 --> 10:43.140
And later on we're going to just make it private.

10:43.140 --> 10:47.880
So let's make public string scene to load.

10:49.130 --> 10:50.900
All right, well, let's do a C name.

10:53.140 --> 10:53.650
All right.

10:53.650 --> 10:54.460
Very nice.

10:54.460 --> 10:56.230
Now, um.

10:58.010 --> 11:00.170
Let's make a method public void.

11:01.630 --> 11:04.930
Lord level and this will do something simple.

11:04.930 --> 11:10.630
Scene manager load scene with a scene name just like we did before with a new game button.

11:10.630 --> 11:17.770
Right now what I want to do is to make a method that will create a button for each level we have in

11:17.770 --> 11:23.140
the project, and then it will assign this variable on its own while creating a button.

11:23.140 --> 11:25.930
For that, we need to go to level selection.

11:25.990 --> 11:30.760
Add component of a new script UI level selection.

11:33.000 --> 11:34.890
Uh, let's go inside of this script.

11:34.890 --> 11:41.490
And over here we want to have reference to the buttons prefab so we can create all of the buttons together,

11:41.670 --> 11:42.480
uh, in the code.

11:42.480 --> 11:44.520
So private UI level button.

11:44.520 --> 11:49.110
I'm going to use a script, not the GameObject, because we're going to need access to the component

11:49.110 --> 11:50.310
of a UI level button.

11:50.310 --> 11:52.560
So let's do button prefab.

11:53.410 --> 11:55.570
And also we need the reference to the parent.

11:55.570 --> 11:59.560
So we're going to do private transform buttons parent.

12:01.020 --> 12:03.540
And we're going to use content.

12:03.960 --> 12:04.590
Sorry.

12:05.810 --> 12:09.560
We're going to use content as a parent for all of the buttons, and because of that, we don't need

12:09.560 --> 12:11.030
to set position or anything else.

12:11.030 --> 12:16.340
We can just make buttons here and they will be aligned automatically because we have this component

12:16.580 --> 12:18.260
of a grid layout group.

12:18.980 --> 12:20.690
So let's go back to script.

12:20.690 --> 12:25.850
And over here we're going to make private void read level buttons.

12:25.850 --> 12:28.850
And first we want to know how many buttons we need to create.

12:28.850 --> 12:32.630
So let's make int levels amount.

12:32.720 --> 12:34.100
How can we check this.

12:34.130 --> 12:38.960
We can do scene manager scene count in build settings.

12:38.960 --> 12:43.490
And this will return us amount of scenes we have uh over here.

12:44.350 --> 12:45.610
In a scene list.

12:46.440 --> 12:50.820
The only change we want to do is we want to exclude the end button.

12:50.850 --> 12:53.520
We're also going to exclude main menu, but in a different way.

12:53.610 --> 12:56.220
As of now we just need to exclude the end.

12:56.220 --> 12:57.660
So how are we going to do this.

12:57.690 --> 13:03.840
We're going to go back to script and type here minus one which means all of them minus one.

13:03.840 --> 13:07.350
Which means again we're going to do all of the scenes except the last one.

13:07.350 --> 13:08.970
Then we're going to make a for loop.

13:09.930 --> 13:11.490
On the levels amount.

13:11.490 --> 13:14.790
And of course we don't want to include the main menu scene.

13:14.790 --> 13:18.360
And if we don't want to do that, we just need to change I to one.

13:18.360 --> 13:20.340
So it will start from one, not from zero.

13:20.340 --> 13:25.650
And because we excluded the last one, it's only going to do that for level since we have and now we're

13:25.650 --> 13:27.750
going to do UI level button.

13:28.620 --> 13:33.180
New button equals to instantiate button prefab.

13:33.740 --> 13:35.480
And over here we can give it a parent.

13:35.480 --> 13:37.940
We're just going to give it buttons parent.

13:38.600 --> 13:39.290
Nice.

13:39.290 --> 13:46.640
Now we want to take new button and give it the index of itself so it knows what level it needs to load.

13:46.640 --> 13:50.870
Let's go to UI level button over here I'm going to make a method.

13:51.830 --> 14:00.800
Public void setup button and this button needs to know int level index or sin index doesn't really matter.

14:00.800 --> 14:04.790
So I'm going to make here private int level index.

14:05.000 --> 14:06.890
And then we're going to do.

14:08.400 --> 14:15.660
This level index or actually, let's just make it as new level index, new level index and is going

14:15.660 --> 14:18.330
to be level index equals to new level index.

14:18.330 --> 14:19.260
Very nice.

14:19.260 --> 14:25.230
Now we can take scene name and make it equals to level underscore.

14:25.260 --> 14:27.510
This is how we have it in the asset folder.

14:27.660 --> 14:32.940
And then plus level index just that that's what we need.

14:32.940 --> 14:37.500
Also I want to write name of the level I mean number of the level on the button itself.

14:37.500 --> 14:42.750
So I'm going to make serialize field private text mesh pro GUI.

14:44.110 --> 14:45.820
Level number text.

14:46.360 --> 14:56.320
And then over here we can do level number text dot text equals to level space plus level index.

14:59.030 --> 15:00.440
It's very good.

15:00.440 --> 15:02.030
Let's save this one then.

15:02.030 --> 15:03.830
Let's go to level selection.

15:03.830 --> 15:05.810
And over here we're going to do a new button.

15:05.810 --> 15:08.360
Set up button with a I.

15:12.560 --> 15:14.630
Now let's call method in the start.

15:14.810 --> 15:15.830
Start.

15:16.220 --> 15:17.750
Create level buttons.

15:18.520 --> 15:19.450
Very good.

15:19.450 --> 15:21.040
Let's go back to unity.

15:21.070 --> 15:26.020
We have levels in the scene list and names are here.

15:26.020 --> 15:30.010
And we did not take the main menu because we started from one.

15:30.010 --> 15:32.710
And also we did not take the end because we did minus one.

15:32.710 --> 15:35.500
Now we can go to this button.

15:35.500 --> 15:37.540
Let's rename it to level.

15:38.470 --> 15:39.460
Button.

15:40.520 --> 15:45.950
We want to assign reference to the text over here, and then we can go to prefab.

15:45.980 --> 15:49.880
Let's make a folder for UI UI.

15:50.150 --> 15:54.050
And then let's drag this level button to UI just like that.

15:54.050 --> 15:56.030
Now we can delete it from the content.

15:56.030 --> 16:00.620
And on the level selection we need to assign this button over here.

16:00.620 --> 16:03.740
And also we want to give parent over here.

16:03.740 --> 16:05.810
So we're going to drag content to this field.

16:05.810 --> 16:07.670
Now let's go to play mode.

16:08.910 --> 16:10.350
And ta da!

16:10.350 --> 16:16.380
We have level one, level two, level three, and each button has a name of a scene that it's supposed

16:16.380 --> 16:21.300
to load level one, level two, level three, and we can click any of them.

16:22.360 --> 16:25.420
And it will not work because I forgot to add on click event.

16:25.990 --> 16:29.200
Let's do it now and let's click add here.

16:29.200 --> 16:33.670
Drag your level button and choose Level Load.

16:33.670 --> 16:37.930
This is supposed to be done in the prefab over here okay let's try again.

16:39.730 --> 16:40.780
And.

16:41.200 --> 16:41.650
Ta da!

16:41.680 --> 16:43.060
I'm on a second level.

16:44.870 --> 16:45.470
Perfect.

16:45.650 --> 16:47.390
This works very well for us.

16:47.390 --> 16:50.450
So this one going to be used when we click Continue game.

16:50.450 --> 16:54.710
And we want to select the level or start from the level that we want.

16:54.710 --> 16:58.730
For example player wants to collect all of the fruits so he wants to start over.

16:58.730 --> 16:59.870
Yeah that is good.

16:59.870 --> 17:01.040
Now what is next.

17:01.040 --> 17:05.600
We need to save the progress of the levels we've completed.

17:05.600 --> 17:08.000
But we're going to do that in another video.

17:08.120 --> 17:14.960
As of now, let's give each scene a knowledge of what the index this scene has.

17:14.960 --> 17:16.820
So I'm going to go to level one.

17:16.820 --> 17:17.990
Let me save it.

17:18.700 --> 17:24.310
We need to take game manager, and on a game Manager script, we can make some sort of a header.

17:24.310 --> 17:27.430
Header level management.

17:27.460 --> 17:31.240
Over here I'm going to do serialize field private int.

17:32.000 --> 17:35.450
Current level index.

17:35.720 --> 17:45.050
And then maybe in the start we can do current level index equals to scene manager get active scene dot

17:45.050 --> 17:46.520
build index.

17:46.700 --> 17:47.690
Very nice.

17:47.690 --> 17:52.130
So now this one has information about the current level index.

17:52.130 --> 17:59.030
And then we're going to go to the level finished method over here.

17:59.030 --> 18:01.640
Or actually where we load the end scene.

18:01.640 --> 18:08.300
And we're going to make another one private void load next level which will do something simple for

18:08.300 --> 18:08.570
us.

18:08.570 --> 18:16.490
It will do int next level index equals to current level index plus one.

18:16.580 --> 18:21.410
Then we're going to do uh scene manager load scene.

18:23.590 --> 18:26.980
Over level underscore plus current.

18:26.980 --> 18:28.810
I mean next level index.

18:28.810 --> 18:33.220
We could use only index in a build settings, but then we would have only numbers in the script.

18:33.220 --> 18:34.720
And that would be a bit confusing.

18:34.720 --> 18:38.590
But if we have string we basically can see that we load in the level.

18:38.590 --> 18:40.900
So that's why I prefer to use name of the scene.

18:41.520 --> 18:46.920
Now in this method, we need to decide if we want to load the next level or the final scene and show

18:46.920 --> 18:48.210
that game is over.

18:48.240 --> 18:51.600
So first of all, we're going to use fade effect two times now in this method.

18:51.600 --> 18:53.940
So that's why I want to do fade effect.

18:54.120 --> 18:59.850
Fade effect equals to UI in game dot instance dot fade effect.

18:59.850 --> 19:02.940
This will help me to type less code over here.

19:02.970 --> 19:03.570
All right.

19:03.570 --> 19:07.440
Now we want to know if there is no more levels in build.

19:07.440 --> 19:10.470
I guess we can do um, bool.

19:10.530 --> 19:22.020
No more levels and this will be equals to true if current level index plus one is equals to the, um,

19:22.020 --> 19:23.400
scene manager.

19:25.130 --> 19:27.110
My brain is not raining today.

19:28.100 --> 19:30.170
Scene count and build settings.

19:30.680 --> 19:31.040
Yeah.

19:31.040 --> 19:32.000
So this is what we have.

19:32.000 --> 19:39.770
And then we're going to do if normal levels then load the end scene else do fade effect screen fade

19:39.770 --> 19:41.240
1.5 f.

19:41.810 --> 19:43.910
Uh load next level.

19:44.690 --> 19:45.680
Very nice.

19:45.680 --> 19:47.870
So what's the idea here?

19:48.140 --> 19:49.550
Uh, let me open.

19:50.910 --> 19:53.310
I'll build profiles, scene list.

19:53.310 --> 19:59.610
And now we can see that, for example, we're doing this check on the last level we have which has index

19:59.610 --> 20:03.360
three three plus one is four.

20:05.060 --> 20:08.570
If and if that is equals to sin counts and builds.

20:09.050 --> 20:10.670
Uh, one, two, three.

20:10.670 --> 20:15.410
Or this is actually should be five because this will count 012, three, four, five.

20:15.410 --> 20:16.940
So this will be five.

20:20.290 --> 20:26.200
Because we need to calculate the, um, oh my God, we need to calculate the amount of levels, but

20:26.200 --> 20:28.030
we don't need to calculate one and two.

20:28.060 --> 20:28.690
So.

20:31.950 --> 20:33.810
Easiest way would be type here.

20:34.170 --> 20:35.220
Last two.

20:36.940 --> 20:38.710
But then that can be very confusing.

20:38.740 --> 20:40.660
So now we need to make it clear somehow.

20:40.660 --> 20:42.790
So it's understandable what we're doing here.

20:43.450 --> 20:44.620
Let's do it this way.

20:44.620 --> 20:50.470
Let's do int last level index equals to scene manager.

20:51.010 --> 20:53.410
Uh scene content build settings minus two.

20:53.890 --> 20:55.690
And I'm going to leave a comment here.

20:56.550 --> 20:57.030
Okay.

20:57.030 --> 20:57.630
Very well.

20:57.630 --> 21:04.890
Now we're going to do if current level index is equals to last level index then there is no more levels.

21:04.890 --> 21:08.550
And if that's the case then we're going to load the end scene.

21:08.550 --> 21:09.300
Very cool.

21:09.300 --> 21:10.530
Now let's save this.

21:10.530 --> 21:12.090
Let's go back to unity.

21:12.980 --> 21:16.280
Uh, over here on the canvas.

21:16.280 --> 21:20.180
We need to change scene name to level one.

21:20.180 --> 21:22.640
And I think it's better to change the variable name.

21:22.640 --> 21:25.730
I'm going to change it to first level.

21:26.870 --> 21:27.590
Name.

21:27.590 --> 21:31.940
Okay, this is better because this one is, uh, loaded with a new game.

21:31.940 --> 21:34.400
This is going to be changed later, but as of now, this is good.

21:36.930 --> 21:39.390
So we're going to do level one here.

21:40.060 --> 21:42.010
And now let's just go and try.

21:42.040 --> 21:43.480
I'm going to go to play mode.

21:46.920 --> 21:48.120
New game.

21:50.850 --> 21:53.520
All right, go forward, go forward!

21:53.520 --> 21:54.480
Let's go.

21:55.630 --> 21:56.020
Now.

21:56.020 --> 21:56.830
Level two.

21:56.860 --> 21:57.700
Perfect.

22:02.290 --> 22:03.880
And oh my.

22:06.420 --> 22:07.680
And level three.

22:07.680 --> 22:08.700
And.

22:09.260 --> 22:10.340
The end.

22:10.370 --> 22:11.750
Nice.

22:11.750 --> 22:12.590
Very nice.

22:12.590 --> 22:13.880
I'm so happy about it.

22:13.880 --> 22:14.870
Very cool.

22:14.870 --> 22:15.470
All right.

22:15.470 --> 22:16.880
We still have much to do.

22:16.880 --> 22:18.560
So let's go to the next video.

22:18.560 --> 22:22.280
We're going to manage new game and continue game button I'll see you there.
