WEBVTT

00:00.140 --> 00:00.530
Hello guys.

00:00.530 --> 00:01.490
Welcome to the video.

00:01.490 --> 00:05.780
So we did a great job with all of the previous sections.

00:05.780 --> 00:10.610
And game is nearly finished in this one we're going to do polish of the game.

00:10.610 --> 00:12.260
We're going to fix some bugs.

00:12.260 --> 00:17.270
If we have them, we're going to fix the issues, maybe change the composition of the game a little

00:17.270 --> 00:20.840
bit and improve some things that could be done better.

00:20.840 --> 00:26.390
For example, we're going to make dust effect or camera shake when Rhino hits the wall, things like

00:26.390 --> 00:26.660
that.

00:26.660 --> 00:32.150
Small things that improves the game overall, but it's not going to change much in the core of the game.

00:32.210 --> 00:32.780
All right.

00:32.780 --> 00:37.250
So first thing I want to do is, uh, decomposition of the game manager.

00:38.060 --> 00:41.990
Let me go to level one and I have game manager here.

00:41.990 --> 00:47.090
So this game manager takes care of making audio manager if we don't have any.

00:47.090 --> 00:49.580
So I want to do this for other managers.

00:49.580 --> 00:54.710
And also our game manager does too many things now, too many things at once.

00:54.710 --> 00:58.730
I did it like that because it was a bit easier just to drop everything into one script.

00:58.730 --> 01:05.210
Uh, but I know for a fact that we're going to have a player manager later on for, uh, local co-op

01:05.210 --> 01:10.580
or version of the game, so we better make a player manager and move some functionality there.

01:10.580 --> 01:15.140
Also, we could make a fruit manager, and then game manager would have reference to all of those things.

01:15.140 --> 01:16.760
Okay, that's what I want to do.

01:16.820 --> 01:20.300
So uh, let's go ahead and do this.

01:22.470 --> 01:24.240
First the player manager.

01:24.240 --> 01:27.510
We have this header of a player and respawn functionality.

01:27.510 --> 01:29.610
And also we're looking for respawn point.

01:29.610 --> 01:32.400
We're going to go ahead and make an empty object.

01:32.400 --> 01:37.620
I'm going to call it player manager and we're going to make a script for this.

01:37.620 --> 01:39.360
Let's do script.

01:40.380 --> 01:42.000
Player manager.

01:44.770 --> 01:45.820
Let me go back.

01:45.820 --> 01:48.070
Put the script on the game object.

01:49.950 --> 01:51.210
Uh, over here.

01:51.210 --> 01:52.950
Then let's open this.

01:52.950 --> 01:59.040
And we want to make it as a public static player manager instance.

01:59.070 --> 02:01.440
Now I'll go to game manager.

02:01.530 --> 02:03.810
I'll copy the awake.

02:04.230 --> 02:05.580
Uh, let's take awake.

02:06.710 --> 02:07.760
Place it here.

02:07.760 --> 02:13.910
Also, when I go to game manager and I want to cut out this header for the player going to cut it out,

02:13.910 --> 02:16.250
go to the player manager, paste it in.

02:16.370 --> 02:20.630
Now it will show me a bunch of errors on the game manager because now we don't have variables, but

02:20.630 --> 02:23.630
we try to use them like these for example.

02:23.750 --> 02:26.300
So I'm going to cut it out here.

02:26.300 --> 02:29.480
Then I'm going to go to player manager over here.

02:29.480 --> 02:31.250
And I'm going to open start method.

02:32.220 --> 02:34.290
And in the start we're going to paste this in.

02:35.750 --> 02:36.470
Okay.

02:36.950 --> 02:37.790
Very nice.

02:37.790 --> 02:41.780
Now we need a respawn method and respawn coroutine.

02:42.200 --> 02:44.990
I'm gonna go ahead all the way below here.

02:44.990 --> 02:47.750
And this is the place we respawn in player.

02:47.750 --> 02:54.890
So I'm going to take these two methods, cut them out, go to player manager and paste them in.

02:55.990 --> 02:56.500
All right.

02:56.530 --> 02:59.500
Now we have this functionality on a separate game object.

02:59.950 --> 03:04.120
By the way, this shows me an error because we need to make using System.collections.

03:04.840 --> 03:06.610
Uh, over here at the top.

03:06.610 --> 03:07.030
Yeah.

03:07.030 --> 03:07.720
This one.

03:11.060 --> 03:11.570
All right.

03:11.570 --> 03:12.980
So we've got the functionality.

03:12.980 --> 03:14.840
Let's save everything.

03:14.840 --> 03:18.650
And now that we saved it, it's going to show me a bunch of errors in different places.

03:18.650 --> 03:21.410
If we go to unity we're going to see them in the console.

03:22.810 --> 03:24.850
So one of them here.

03:25.740 --> 03:28.380
On a dead zone once we respawn the player.

03:28.380 --> 03:32.700
So we're going to change it from game manager to player manager.

03:33.630 --> 03:34.410
Just that.

03:34.860 --> 03:36.270
Uh, let's go back.

03:36.270 --> 03:39.060
Let's see another one over here.

03:39.060 --> 03:40.200
We're using game manager.

03:40.200 --> 03:43.230
We just need to do layer manager.

03:43.230 --> 03:48.600
By the way this method over here, we're going to do it in a different way a bit later on.

03:48.600 --> 03:49.200
All right.

03:49.200 --> 03:53.640
Because now if player dies there is still a second before he responds.

03:53.640 --> 03:55.470
And enemy cannot detect him.

03:55.470 --> 03:57.780
It doesn't break the game, but it happens.

03:58.500 --> 04:00.270
Uh, let's go here now.

04:01.250 --> 04:03.470
Over here we have update respawn point.

04:03.830 --> 04:06.920
And by the way this should be moved to player manager.

04:06.920 --> 04:08.300
So I'm going to take it.

04:08.810 --> 04:12.050
Go to Player Manager and paste it in here.

04:13.200 --> 04:14.040
All right.

04:14.070 --> 04:15.030
Very good.

04:15.060 --> 04:18.090
Now let's save everything like that.

04:18.540 --> 04:21.510
And I guess we're going to have a couple of more errors.

04:21.810 --> 04:23.160
Let's go to unity.

04:23.340 --> 04:25.260
There is one on the checkpoint.

04:25.830 --> 04:29.250
So here we call in method update respawn point.

04:29.250 --> 04:33.150
We need to replace it with a player manager like that.

04:34.020 --> 04:34.740
Good.

04:34.740 --> 04:35.910
Very good.

04:36.210 --> 04:38.160
Now let's go back.

04:41.720 --> 04:44.930
I'm going to go ahead and assign prefab over here.

04:45.470 --> 04:46.520
Prefab.

04:46.550 --> 04:47.390
There is a player.

04:47.390 --> 04:49.400
So we're going to give it over here.

04:50.230 --> 04:55.600
And then I want to go to prefab folder and make a player manager as a prefab.

04:55.900 --> 05:02.200
And then we're going to go to game manager and ask it to check if we don't have player manager in the

05:02.200 --> 05:05.710
game, because if we don't have to, we need to create one.

05:06.550 --> 05:08.320
We just need the reference over here.

05:08.320 --> 05:13.450
Serialized field, private game player manager, player manager.

05:13.750 --> 05:17.020
Then we're going to go back to the method we have over here.

05:17.020 --> 05:19.000
Create managers if needed.

05:19.890 --> 05:22.950
And we're going to do this if player manager.

05:24.060 --> 05:28.140
That instance equals to null, then instantiate layer Manager.

05:28.140 --> 05:29.250
Simple as that.

05:29.250 --> 05:34.530
If you like, you can pass managers to the next level with a don't destroy game object, but I don't

05:34.530 --> 05:35.400
think it's necessary.

05:35.400 --> 05:37.620
This is just for us while we testing this.

05:38.310 --> 05:38.760
Um.

05:40.240 --> 05:40.810
Here.

05:40.840 --> 05:41.620
Very good.

05:41.620 --> 05:46.900
So let's go to prefabs now and assign these on the game manager like that.

05:46.900 --> 05:48.970
Now we need to apply overrides.

05:50.410 --> 05:54.160
So this change will be applied to all of the game managers on all levels.

05:54.190 --> 05:57.970
I'm going to click apply and I'm going to delete player manager just so I can check it.

05:59.510 --> 06:00.590
Also on the player manager.

06:00.590 --> 06:01.790
Over here we have prefab.

06:01.790 --> 06:02.030
Okay?

06:02.030 --> 06:02.630
It's fine.

06:02.630 --> 06:04.190
So don't have player manager.

06:04.190 --> 06:06.530
I'm going to go to play mode and.

06:07.200 --> 06:08.400
Now we've got one.

06:09.260 --> 06:12.050
And if I die, it will create a new one.

06:12.080 --> 06:15.470
Although I cannot die now because I'm on easy difficulty.

06:15.560 --> 06:19.520
And we also need difficulty manager in the game just to test different things.

06:19.520 --> 06:21.590
So I'm going to go ahead and make.

06:23.780 --> 06:24.140
Sorry.

06:24.140 --> 06:24.920
We don't need to make it.

06:24.920 --> 06:27.410
We have it on the scene of a main menu.

06:27.410 --> 06:29.060
Let's go to main menu.

06:30.300 --> 06:31.620
Can I save the changes?

06:32.650 --> 06:38.770
Can I go to prefabs, drag skin manager and difficulty manager and drag them here like that?

06:39.720 --> 06:40.500
Okay.

06:40.500 --> 06:43.440
Very cool on the skin, manager.

06:43.470 --> 06:44.400
Yeah, we have it.

06:44.400 --> 06:44.730
Okay.

06:44.730 --> 06:45.540
It's fine.

06:45.540 --> 06:46.980
We have it as an instance.

06:46.980 --> 06:49.470
Then let's go back to the scene.

06:49.470 --> 06:50.340
Level one.

06:51.340 --> 06:54.430
And we want to do this for those two managers as well.

06:54.430 --> 07:00.970
So on the game manager I'm going to make variable serialized field private skin manager.

07:02.160 --> 07:03.150
Centralized field.

07:03.150 --> 07:05.490
Private, uh, difficulty manager.

07:06.060 --> 07:06.900
Nice.

07:07.140 --> 07:09.000
And we can go back to that method.

07:10.840 --> 07:14.410
Over here and we need to do these checks as well if skin manager.

07:15.360 --> 07:18.240
That instance equals to null, then instantiate skin manager.

07:18.240 --> 07:22.170
If difficulty manager equals to null, then instantiate.

07:23.010 --> 07:25.260
Difficult to manage are very good.

07:25.260 --> 07:27.930
So now it will create one if we need to test different things.

07:27.930 --> 07:34.770
For example, now I need to test death of the character and I don't have difficulty manager in the scene,

07:34.770 --> 07:37.080
but it's okay, it will be created for me.

07:37.410 --> 07:40.230
Difficulty manager, skin manager.

07:40.230 --> 07:41.190
Let's go.

07:43.870 --> 07:44.560
Okay.

07:44.560 --> 07:47.740
It is where it is.

07:47.740 --> 07:48.340
There.

07:48.340 --> 07:52.420
I'm going to do hard and I'll go and try to kill myself.

07:52.750 --> 07:53.260
You.

07:54.340 --> 07:58.510
All, my character does not die because we did not update it on the.

07:59.610 --> 08:00.390
Layer.

08:00.390 --> 08:06.720
Over here we have a variable of a game difficulty and we update it at the start.

08:12.070 --> 08:16.120
How can we update the difficulty just in case?

08:20.850 --> 08:21.870
Peak definition.

08:21.870 --> 08:23.460
This is a private method.

08:23.490 --> 08:25.470
Let's make it public.

08:26.810 --> 08:28.040
Let's make it public.

08:30.470 --> 08:34.880
Actually, I guess it can be private and we can just make a context menu.

08:36.530 --> 08:38.750
And we can just do a context menu.

08:40.040 --> 08:42.590
Uh, update difficulty.

08:43.040 --> 08:44.120
There are many ways to do that.

08:44.120 --> 08:47.810
We could make it just like the variable could be visible in the inspector.

08:49.130 --> 08:50.720
Actually, that would be the simplest way.

08:50.720 --> 08:51.920
Why don't I think of it?

08:51.920 --> 08:53.780
Oh my God, I'm so sorry, guys.

08:53.780 --> 08:56.810
Let's go and just make it as serialized field.

08:56.810 --> 08:58.670
So now we can easily test it.

08:58.670 --> 09:00.230
This was the easiest decision.

09:00.230 --> 09:01.520
I mean, way to fix it.

09:01.550 --> 09:05.390
Why didn't I, uh, you know, sometimes it can be like that.

09:05.390 --> 09:08.150
You don't think of best decision at first.

09:10.060 --> 09:10.720
Okay.

09:10.720 --> 09:14.560
So hard difficulty going to go ahead and.

09:15.360 --> 09:18.690
Hugh, I died and I have all of the managers in the game.

09:18.690 --> 09:19.470
Very good.

09:19.500 --> 09:24.120
Of course, this will not be changed because we are testing seen, but if you start the game from main

09:24.120 --> 09:25.530
menu, it's going to be fine.

09:25.560 --> 09:29.490
Now regarding the game manager, it still does lots of things.

09:29.490 --> 09:36.030
For example, it does take care of a trap of creating an object, and I think we can make some sort

09:36.030 --> 09:42.210
of object creator game object, and then we can call that game object if we need to create some object

09:42.210 --> 09:46.620
with a delay, and we cannot do it from any other place, just like we have with the arrow, because

09:46.620 --> 09:51.270
I suppose some of you want to respawn falling platforms once they fell, and then we would have to add

09:51.270 --> 09:52.500
variable to game manager.

09:52.500 --> 09:55.470
And game manager is kind of responsible for other things.

09:56.130 --> 09:59.250
So let's go to scripts.

10:00.230 --> 10:02.480
I think we can do it in the managers folder.

10:03.450 --> 10:04.680
I'm going to make.

10:05.970 --> 10:07.770
Object creator.

10:10.470 --> 10:12.180
Uh, where is it?

10:12.660 --> 10:14.040
Object creator.

10:14.070 --> 10:19.440
Let's make it as a public static object creator instance.

10:19.620 --> 10:21.450
Then we're going to do a wake.

10:21.450 --> 10:25.980
And we need functionality from any manager we have from here.

10:25.980 --> 10:29.100
For example I'm going to take it paste it in here.

10:29.100 --> 10:30.930
Then let's go to Game Manager.

10:33.130 --> 10:34.900
And let's take.

10:35.660 --> 10:37.820
These create object and create object.

10:37.820 --> 10:40.130
Coroutine gonna cut it out.

10:40.250 --> 10:43.700
Go back paste it in here.

10:44.350 --> 10:44.920
What is it?

10:44.920 --> 10:47.380
Instance.

10:47.410 --> 10:48.130
Okay.

10:48.430 --> 10:50.440
We need using system collection.

10:50.440 --> 10:53.350
Using system collections.

10:55.850 --> 10:59.420
And now we need header with references and it's good to go.

10:59.450 --> 11:01.370
Let's go to.

11:05.000 --> 11:05.630
Here.

11:05.630 --> 11:06.680
Let's take it.

11:07.430 --> 11:09.410
Go back to Object Creator.

11:10.280 --> 11:11.480
Paste it in here.

11:12.250 --> 11:15.100
And then it's basically it.

11:15.100 --> 11:17.380
Now we're going to have a bunch of errors that we need to fix.

11:17.380 --> 11:23.800
And also let's make a serialized field private object creator, object creator.

11:23.890 --> 11:28.150
And then over here if object creator.

11:29.580 --> 11:33.810
Dot instance equals to null, then instantiate object creator.

11:33.840 --> 11:34.590
Nice.

11:34.590 --> 11:36.540
Now let's go and fix those errors.

11:36.750 --> 11:40.530
And one of them will be on the trap arrow.

11:41.370 --> 11:51.540
Because we are using a game manager here, so we can do object creator instead, as well as here object

11:51.540 --> 11:53.130
creator instead.

11:53.580 --> 11:59.370
Okay, if you have any other functionality that used Game Manager to create an object, you can change

11:59.370 --> 12:00.090
it now.

12:01.600 --> 12:05.650
And we only need to go and make the prefab of object Creator.

12:05.650 --> 12:08.770
Let's make object creator.

12:08.770 --> 12:13.090
Let's put the script on and let's find arrow Prefab.

12:14.970 --> 12:16.140
Uh, traps.

12:17.700 --> 12:18.390
Arrow.

12:19.070 --> 12:22.340
And I'm going to just go to prefabs, make it here.

12:22.340 --> 12:26.600
And I think we can make a folder for managers now managers.

12:29.000 --> 12:31.250
Gonna take it all.

12:32.420 --> 12:34.490
And put them into managers.

12:34.490 --> 12:35.060
Boom!

12:35.330 --> 12:36.620
Very clean and nice.

12:36.650 --> 12:38.090
Now this one is here.

12:38.090 --> 12:39.050
I'm going to apply.

12:39.050 --> 12:39.620
Oh it's okay.

12:39.620 --> 12:41.060
We don't need to apply overwrites.

12:41.270 --> 12:43.040
And now it's good to go.

12:43.040 --> 12:47.000
We only need to assign it here on a game manager object creator.

12:47.000 --> 12:47.960
Nice.

12:47.960 --> 12:55.940
Now game manager is only responsible for creating other managers, for collecting fruits and for loading

12:55.940 --> 12:57.530
the levels and saving info.

12:57.530 --> 13:02.270
Still kinda a lot like we could decompose the fruits functionality.

13:03.110 --> 13:06.080
Uh, but I'm not sure it's necessary for now.

13:06.080 --> 13:06.800
I think it's fine.

13:06.800 --> 13:10.760
I think we're not going to do anything with fruits for now, because it's just fruits and.

13:10.760 --> 13:11.180
Yeah.

13:12.430 --> 13:15.550
Uh, maybe I would only make a fruit parent.

13:16.620 --> 13:19.590
Public transform route.

13:19.590 --> 13:20.340
Parent.

13:22.260 --> 13:26.700
And then when we collecting the fruits info I'm going to do this.

13:26.700 --> 13:35.580
If fruit parent is not equals to null, then uh, I'll just move this above like that and then I'll

13:35.580 --> 13:36.090
do.

13:36.120 --> 13:36.810
No sorry.

13:36.810 --> 13:37.710
Let's not do it here.

13:37.710 --> 13:39.720
Let's make another method and let's make it.

13:39.720 --> 13:43.500
Let's make private void parent all the fruits.

13:43.500 --> 13:48.510
Because you might have lots of fruits in the game and you want to find the parent for them, so you

13:48.510 --> 13:53.130
don't clutter up the hierarchy, because it's kind of difficult to manage when you have lots of objects

13:53.130 --> 13:54.060
in the hierarchy.

13:54.060 --> 14:01.200
So I'm going to do this, uh, if fruit parent equals to null, then return.

14:01.200 --> 14:05.520
And if no we're going to take this line of code over here, paste it in here.

14:05.520 --> 14:06.930
And then for each.

14:08.300 --> 14:09.140
Fruit.

14:09.140 --> 14:10.850
Fruit in all fruits.

14:11.360 --> 14:12.020
Fruit.

14:12.050 --> 14:15.320
Transform parent equals to fruit parent.

14:16.230 --> 14:18.810
So we're going to parent all of the objects if we want to.

14:18.810 --> 14:24.060
And let's make context menu for this context menu parent all fruits.

14:24.780 --> 14:25.650
Good.

14:25.680 --> 14:28.920
Now let's save this and let's go back.

14:30.040 --> 14:34.510
Now, if you want to clean up the hierarchy because it's kind of difficult to manage it.

14:34.510 --> 14:42.670
You can make fruit errant and you can find game manager, give it a fruit parent and then just click

14:42.670 --> 14:44.140
Parental Fruits.

14:44.410 --> 14:46.600
And now they'll be here altogether.

14:46.600 --> 14:48.220
And if you want you can switch them off.

14:50.210 --> 14:50.930
Cool.

14:51.950 --> 14:53.960
Well, that's it for now.

14:53.960 --> 14:58.310
Thank you so much for paying attention and taking the time to clean this up.

14:58.430 --> 15:05.120
Uh, again, we could separate fruit management somewhere else, maybe as well as a checkpoints, but

15:05.120 --> 15:08.090
as of now, this is pretty manageable, so I think it's fine.

15:08.510 --> 15:09.110
Yeah.

15:10.200 --> 15:16.770
Because we need to pass the fruit's info when we save, uh, the game, when we collect the fruits,

15:16.770 --> 15:20.280
all of that needs to be done with playerprefs and everything.

15:20.280 --> 15:24.870
So if we want to make fruit manager, then we would have to pass the reference, or we would have to

15:24.870 --> 15:26.880
use Playerprefs in two different scripts.

15:26.880 --> 15:28.200
And that can be a bit confusing.

15:28.200 --> 15:30.990
It's better to have everything together like we have now.

15:30.990 --> 15:32.610
Okay, okay.

15:32.730 --> 15:33.450
That's good.

15:33.450 --> 15:34.830
Let's go to the next video.

15:34.860 --> 15:36.690
We're going to do more foolish.
