WEBVTT

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

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

00:01.460 --> 00:03.230
So we basically done with this section.

00:03.230 --> 00:07.940
There is nothing much to do and we don't really need to do any cleanup because I try to be careful.

00:07.940 --> 00:10.610
And we did not write lots of code here so it should be fine.

00:10.610 --> 00:16.490
I just want to congratulate you, maybe because we are pretty close to the end of the course and I know

00:16.490 --> 00:17.390
it's a big achievement.

00:17.390 --> 00:22.670
So yeah, sorry, that was not very enthusiastic, but I'm really happy and I congratulate you.

00:22.670 --> 00:23.690
So yeah.

00:23.720 --> 00:24.380
Good job.

00:24.380 --> 00:26.420
Now I'm going to wrap this project into archive.

00:26.420 --> 00:28.670
I'm going to give it to you if you want to compare it to yours.

00:28.700 --> 00:34.190
And I'll just do this I'll disable settings and I'll enable main menu like that.

00:34.190 --> 00:39.380
And also before I give this project to you, I'm going to go to audio Background music.

00:39.380 --> 00:42.920
And I'm going to delete these two tracks just to make my project lighter.

00:42.920 --> 00:44.810
And if you need them you know where to get them.

00:44.810 --> 00:47.360
You can just download them from the asset store.

00:47.360 --> 00:52.880
Now you'll have these tracks over here, but it will say Missing Audio Source, so probably you will

00:52.880 --> 00:54.290
not be able to play it.

00:54.560 --> 00:56.120
Maybe just in case.

00:56.120 --> 00:57.350
Let's go.

00:58.790 --> 01:00.140
To the audio manager.

01:00.260 --> 01:04.760
And when we play BGM over here, we're going to do this.

01:04.760 --> 01:10.340
If BGM dot length is less or equals to zero, then return.

01:10.340 --> 01:16.670
So we will not start this invoke repeating method and we will not do check for the BGM and maybe we

01:16.670 --> 01:17.690
can do same here.

01:17.690 --> 01:18.230
I'm going to do.

01:18.260 --> 01:26.300
If BGM dot length is less or equals to zero, then I'm going to return and I'm going to say debug log.

01:26.300 --> 01:27.230
Warning.

01:27.230 --> 01:31.730
You have no music on Audio Manager.

01:32.480 --> 01:33.350
All right.

01:33.350 --> 01:36.710
Just to protect ourselves from a possible mistake.

01:36.710 --> 01:37.130
Oh, yes.

01:37.130 --> 01:38.150
And something else.

01:38.150 --> 01:39.050
Something important.

01:39.050 --> 01:40.070
I forgot about this.

01:40.100 --> 01:44.360
If you go to the scene right now, it will not have an audio manager.

01:44.360 --> 01:45.320
This one will have.

01:45.320 --> 01:48.020
But for example, level two does not have an audio manager.

01:48.020 --> 01:51.590
And once you start the game, it's going to try to request audio manager.

01:51.590 --> 01:55.370
And you're going to see an errors and game will not work as needed.

01:55.370 --> 01:58.790
So somehow we need to bypass this limitation.

01:59.610 --> 02:04.470
We can go to prefabs and make game manager as a prefab.

02:04.500 --> 02:06.180
That's first step.

02:07.890 --> 02:10.410
And let's change the name to.

02:11.730 --> 02:14.760
Uh, game manager with the underscores here.

02:14.790 --> 02:15.390
Okay.

02:15.720 --> 02:16.380
One, two.

02:16.380 --> 02:17.430
Three underscores.

02:17.430 --> 02:17.700
One.

02:17.700 --> 02:17.910
Two.

02:17.910 --> 02:18.360
Three.

02:18.360 --> 02:19.050
Okay.

02:19.140 --> 02:21.420
And we're going to go to game manager.

02:21.690 --> 02:25.320
And we're going to make a reference to the prefab of audio manager.

02:27.720 --> 02:29.340
I'm going to make a header.

02:29.460 --> 02:30.810
Managers.

02:31.170 --> 02:36.870
And then I'm going to do serialize field private audio manager.

02:39.330 --> 02:40.380
Audio manager.

02:40.990 --> 02:45.820
Then we need to make a method that would check if we don't have audio manager in the scene.

02:46.390 --> 02:48.700
Let's go and make a method.

02:49.970 --> 02:51.650
And to this private void.

02:51.860 --> 02:55.250
Create managers if needed.

02:55.790 --> 02:57.410
And then inside of this method.

02:57.410 --> 02:59.030
This method is going to be called in the start.

02:59.030 --> 03:01.850
Once all of the instances are supposed to be assigned.

03:01.850 --> 03:07.190
And because of that, we can check if we have an instance of audio manager, and if we don't, we have

03:07.190 --> 03:08.960
to create it real fast.

03:08.960 --> 03:10.820
And this is how I'm going to do it.

03:10.820 --> 03:12.200
I'm going to make.

03:13.180 --> 03:14.020
If statement.

03:14.020 --> 03:21.730
If audio manager audio manager dot instance is equals to null means we don't have it in this scene,

03:21.850 --> 03:23.770
then we can do instantiate.

03:24.630 --> 03:25.620
Audio manager.

03:28.070 --> 03:29.060
Just like that.

03:29.570 --> 03:34.910
Let's go to start method and do, uh, create managers if needed.

03:35.480 --> 03:39.830
And I believe it's supposed to work, but maybe it will not let me just.

03:40.790 --> 03:42.080
And double check it.

03:43.510 --> 03:46.210
We need to go to the game manager.

03:46.840 --> 03:49.960
We need to find prefab of the audio manager.

03:51.430 --> 03:59.110
Drag it here, then we need to apply overrides so it has auto manager on all of the prefabs.

03:59.110 --> 04:00.400
Then we need to go.

04:00.490 --> 04:01.780
Let's just check it first.

04:02.530 --> 04:03.880
Let's go to play mode.

04:06.920 --> 04:08.450
And it works.

04:08.450 --> 04:09.230
It's fine.

04:09.230 --> 04:11.810
And we have audio manager here.

04:11.840 --> 04:12.650
All right.

04:12.650 --> 04:13.760
This is good.

04:13.790 --> 04:18.260
Now let's go to asset scene level one.

04:19.070 --> 04:19.820
And over here.

04:19.820 --> 04:25.670
We need to delete this audio manager and replace it with audio manager that we have prefab I mean game

04:25.670 --> 04:26.270
manager.

04:26.270 --> 04:27.140
Game manager.

04:27.170 --> 04:27.800
Okay.

04:27.860 --> 04:31.520
This one can be deleted and game manager is here.

04:31.520 --> 04:36.920
We don't have respawn point assigned but I believe it's supposed to be done automatically.

04:38.040 --> 04:39.930
Is it done automatically?

04:39.960 --> 04:42.240
No, it is not.

04:43.570 --> 04:44.470
Let me check.

04:44.470 --> 04:45.490
Start point.

04:46.380 --> 04:47.760
It is not okay.

04:47.760 --> 04:50.940
We need to find start point if we did not assign it manually.

04:52.180 --> 04:53.380
Just in case.

04:56.610 --> 04:58.920
Um, for now, let's do it like that.

05:00.330 --> 05:04.800
Landstorm if respawn point is equals to null.

05:05.980 --> 05:10.630
Then respawn point equals to find object of type.

05:11.680 --> 05:13.120
Start point.

05:13.990 --> 05:16.600
And it shows me an error because it was changed.

05:16.600 --> 05:18.400
A new unity version.

05:18.880 --> 05:21.850
And we need to do find first object by type.

05:21.850 --> 05:23.140
Okay, I'm so sorry.

05:23.380 --> 05:25.900
Not off type, but by type.

05:25.900 --> 05:31.120
Find first object by type of start point.

05:32.120 --> 05:33.020
Transform.

05:33.020 --> 05:38.600
Okay, so this will find the respawn point if you forget to assign it manually, right?

05:40.000 --> 05:40.960
Let's go back.

05:44.730 --> 05:46.320
And I'm going to go to game mode.

05:46.320 --> 05:47.850
Respawn point is empty.

05:51.470 --> 05:53.180
Okay, we need a respawn player.

05:53.180 --> 05:54.410
There is audio manager.

05:54.410 --> 05:59.090
Everything is good and we need to replace it on other levels.

06:02.410 --> 06:04.600
Let's go to scene level three.

06:05.200 --> 06:06.280
Save it.

06:08.100 --> 06:10.950
When I go to a prefab now, I'm going to go to prefab folder.

06:10.950 --> 06:14.820
I'm going to drag this game manager over here and this one can be deleted.

06:15.360 --> 06:16.380
Okay.

06:16.380 --> 06:17.580
Something else.

06:17.580 --> 06:21.420
Probably no asset seen level four.

06:21.450 --> 06:21.810
Yes.

06:21.810 --> 06:25.110
Let's save the changes I'm going to delete this one.

06:25.110 --> 06:29.190
Going to go to prefab and take Game Manager over here.

06:29.190 --> 06:30.090
Cool.

06:30.090 --> 06:32.340
Now let me double check it on this level.

06:34.790 --> 06:35.720
Okay.

06:35.720 --> 06:37.070
There was some error.

06:37.100 --> 06:37.640
Let me see.

06:37.640 --> 06:38.390
What is it?

06:40.230 --> 06:43.230
Enemy mushroom cannot update reference to the player.

06:44.340 --> 06:45.750
Uh, for some reason.

06:47.790 --> 06:50.280
Because this field is empty over here.

06:50.310 --> 06:52.320
Okay, let's quickly fix it.

06:52.320 --> 06:55.230
We're going to go to game manager and do the same for the player.

06:55.680 --> 06:59.430
And just in case, later on, I think I'll find a better way to manage this.

06:59.430 --> 07:02.670
Just in the next section we're going to do it in a bit cleaner way.

07:02.670 --> 07:06.600
But as of now, let's just fix the problem that we have right now I'm going to do.

07:06.630 --> 07:14.130
If player is equals to null, then player equals to find first object by type player.

07:15.410 --> 07:16.520
And that's it.

07:17.880 --> 07:22.980
Yeah, I know it's a clean up video and we could do it now, but this is more about audio manager.

07:22.980 --> 07:26.460
So yeah, we were fixing audio manager and this just got in the way.

07:26.460 --> 07:27.870
So we fixed it quickly.

07:27.870 --> 07:31.410
In the next section I'm going to show you how to make it better.

07:33.280 --> 07:33.790
As of now.

07:33.790 --> 07:35.080
Let me just double check.

07:37.190 --> 07:37.730
Okay.

07:37.730 --> 07:39.050
No errors.

07:39.260 --> 07:40.730
Very cool.

07:46.150 --> 07:47.770
Nice little design, by the way.

07:48.370 --> 07:48.760
Good job.

07:48.760 --> 07:49.390
Alex.

07:51.560 --> 07:52.580
Yes.

07:52.580 --> 07:53.900
The end of the game.

07:53.900 --> 07:54.800
Okay.

07:54.800 --> 07:55.370
Great job.

07:55.370 --> 07:57.320
In this video we created the manager.

07:57.320 --> 07:58.820
We cleaned up a couple of.

07:58.880 --> 08:02.840
We created a manager, we cleaned up a couple of errors we had.

08:02.840 --> 08:05.750
And that's good I'm going to wrap this project into archive.

08:05.750 --> 08:08.510
I'm going to give it to you and I'll see you in the next section.
