WEBVTT

00:00.170 --> 00:00.650
Hello guys.

00:00.650 --> 00:01.550
Welcome to the video.

00:01.550 --> 00:06.950
So I did double check regarding the background music and it's played one after another, so it should

00:06.950 --> 00:07.400
be fine.

00:07.400 --> 00:09.500
We have no reason to worry about that.

00:09.710 --> 00:13.100
And now let's set up the settings we have in the game.

00:14.130 --> 00:16.830
So I'm going to just make a script.

00:18.100 --> 00:22.450
In the scripts UI, we're going to need UI settings.

00:22.960 --> 00:25.240
UI settings.

00:25.720 --> 00:26.530
All right.

00:27.160 --> 00:28.690
Let's go and find it.

00:29.830 --> 00:35.320
And in this script, we're going to set up, uh, volume according to the slider value we have in the

00:35.320 --> 00:35.890
UI.

00:36.460 --> 00:43.420
Uh, but before we do that, we need to go to the audio and we're going to need to make audio mixer

00:43.690 --> 00:47.200
that is done through create audio audio mixer.

00:49.110 --> 00:51.180
Let's call it audio mixer.

00:51.210 --> 00:52.290
Just like that.

00:52.590 --> 00:57.000
And then we need to go to window audio.

00:57.030 --> 00:58.080
Audio mixer.

00:58.440 --> 00:58.950
Okay.

00:58.950 --> 01:01.050
And there is a window for audio mixer.

01:01.050 --> 01:06.150
With the help of this mixer we can adjust volume of different sound groups.

01:06.330 --> 01:08.490
We just need to select it over here.

01:08.490 --> 01:12.570
Then we need to go to groups and we need to hit plus.

01:12.570 --> 01:15.360
And one of them will be background music.

01:15.660 --> 01:17.790
Then we need to hit plus again.

01:18.090 --> 01:19.590
Uh, but not as a child.

01:19.590 --> 01:20.100
I'm sorry.

01:20.100 --> 01:25.260
We need to select master and add sound effects.

01:25.260 --> 01:29.550
So now we have two mixers that can control volume of the sound.

01:29.550 --> 01:34.200
And we're going to just pass the value from a slider into this mixer.

01:34.200 --> 01:37.530
And thanks to that it's going to adjust sound volume.

01:37.620 --> 01:39.360
Uh, but before we do that.

01:40.540 --> 01:42.370
We need to open the.

01:44.170 --> 01:45.850
Uh, background music we have.

01:46.060 --> 01:50.260
And for the output, we need to choose background music.

01:50.380 --> 01:52.960
Then we need to take all of the sound effects.

01:52.960 --> 01:56.500
And for the output, we need to choose sound effects.

01:56.500 --> 02:00.580
So even now with the setup here we can go to play mode.

02:02.600 --> 02:04.400
And we can increase.

02:04.880 --> 02:07.670
Sorry, we can increase volume of the background music.

02:07.670 --> 02:09.290
Just with help of this slider.

02:09.290 --> 02:11.720
We only need to allow edit and play mode.

02:11.750 --> 02:15.410
Okay, so let me just try that out.

02:20.420 --> 02:21.950
And you can see it works.

02:21.950 --> 02:26.600
Now the goal is to pass value from the slider onto mixer.

02:27.020 --> 02:31.940
For that, we're going to need to expose parameters of this mixer over here.

02:31.940 --> 02:33.860
So we're going to click here.

02:33.860 --> 02:37.850
And actually we can do that by clicking here.

02:37.850 --> 02:42.470
Wait where is the button I yeah I'm sure there is a button over here.

02:42.470 --> 02:42.740
Yeah.

02:42.740 --> 02:43.190
Over here.

02:43.190 --> 02:47.150
We need to do expose volume of background music to script.

02:47.870 --> 02:48.410
Nice.

02:48.410 --> 02:49.670
Now we have a parameter.

02:49.760 --> 02:52.880
We're going to just rename it to BGM.

02:53.480 --> 02:55.700
Then we're going to select Sound effect.

02:55.700 --> 02:59.930
Click right button expose volume of sound effect to script.

03:00.290 --> 03:04.700
Let's find it and let's change it to SFX.

03:05.850 --> 03:06.390
Perfect.

03:06.390 --> 03:07.380
Very nice.

03:07.470 --> 03:10.560
Now let's go to Canvas Settings.

03:10.560 --> 03:14.820
And over here we need to add component UI settings that we have.

03:15.240 --> 03:17.580
After that we need to do something very simple.

03:17.580 --> 03:19.710
We need to go to the script.

03:19.710 --> 03:23.580
And above we're going to make a header under.

03:25.190 --> 03:26.030
Sorry.

03:26.180 --> 03:27.890
So fixed settings.

03:27.890 --> 03:30.830
And under this header we're going to do serialized field.

03:30.830 --> 03:34.550
Private slider is going to be reference to the component of a slider.

03:34.550 --> 03:36.080
So we can get value from there.

03:36.080 --> 03:37.850
Let's call it a suffixed slider.

03:37.850 --> 03:44.990
Then we're going to need serialized field private text mesh pro GUI a suffix slider text.

03:44.990 --> 03:50.930
Because I want to display the percentage of the value to the player so he can understand what the volume

03:50.930 --> 03:51.890
level he has.

03:51.920 --> 03:57.800
And then we need serialized field private string as a fix parameter.

03:57.800 --> 04:01.190
And that is the parameter we just exposed in the BGM.

04:01.190 --> 04:05.930
Now we need to have a header for another one BGM settings.

04:06.760 --> 04:14.320
So I'm going to do Serialized field, Private slider, BGM slider, then Serialized Field Private Text

04:14.320 --> 04:15.460
Mesh Pro.

04:16.310 --> 04:19.070
Guy Kkae-geum slider.

04:19.070 --> 04:21.230
Text and sterilize field.

04:21.230 --> 04:25.370
Private string BGM parameter noise.

04:25.790 --> 04:26.060
Uh.

04:26.060 --> 04:27.050
Almost ready.

04:27.470 --> 04:30.560
We just need a reference to the audio mixer itself.

04:30.560 --> 04:34.070
So I'm going to do serialize field private audio mixer.

04:35.120 --> 04:36.710
Audio mixer.

04:37.680 --> 04:38.400
Nice.

04:38.400 --> 04:43.710
Now, before we go further and assign these parameters, we can just make a method to make it all work

04:43.710 --> 04:44.730
like all together.

04:44.730 --> 04:45.300
Right?

04:45.330 --> 04:51.480
Let's make a public void a suffix slider value.

04:51.480 --> 04:54.090
And we need to pass a float value here.

04:54.090 --> 05:00.300
So in this case the value will be passed when we move the slider in the UI.

05:00.330 --> 05:01.530
That's what we're going to do.

05:01.530 --> 05:10.770
And then over here we're going to do audio mixer set float of as a fixed parameter to the value we pass

05:10.770 --> 05:11.160
in.

05:11.340 --> 05:16.770
And let's go ahead and just test this with one slider because there is an issue that we need to fix.

05:16.770 --> 05:19.350
And before we fix that I want to show you what's there.

05:19.800 --> 05:21.900
Like the problem is you know.

05:22.600 --> 05:23.170
Yeah.

05:23.170 --> 05:27.670
So let's go ahead and find audio mixer for this one.

05:27.670 --> 05:29.740
Then we need to open settings.

05:31.350 --> 05:37.740
BGM volume and SFX volume, and we need to assign slider over here just so we don't see them with the

05:37.740 --> 05:38.340
same name.

05:38.340 --> 05:43.650
I'm going to rename this to slider BGM and this will be slider suffix.

05:44.690 --> 05:46.700
All right, back to settings.

05:46.700 --> 05:52.280
Let's drag slider of Sound Effects and slider of background music.

05:53.210 --> 05:54.020
For the text.

05:54.020 --> 05:57.110
We did not make the object yet, so let's wait for it.

05:57.110 --> 06:02.630
And then for the parameter we need to type suffix bgm.

06:03.020 --> 06:07.700
Okay, I'm going to switch off main menu and I'm going to enable settings.

06:09.130 --> 06:13.480
And yeah, let's just go ahead and see this.

06:13.480 --> 06:14.800
Let's go to play mode.

06:16.650 --> 06:21.600
You know what, it would be better to test this with a background, honestly.

06:21.600 --> 06:27.000
So I'm going to make a public void BGM slider value.

06:27.000 --> 06:28.470
Float value.

06:30.260 --> 06:31.940
Then, uh, sorry.

06:31.940 --> 06:37.550
Audio mixer set float of BGM parameter to the value.

06:37.550 --> 06:41.750
Okay, let's save this and let's go and try this with the background music because background music

06:41.750 --> 06:42.470
is always playing.

06:42.470 --> 06:43.910
So it's easier that way.

06:45.700 --> 06:49.630
Okay, so you can see I'm dragging the slider.

06:52.420 --> 06:53.440
And wait.

06:53.440 --> 06:54.490
It does not work at all.

06:54.490 --> 06:56.950
Give me a second why it's not working?

06:56.950 --> 06:58.840
Because I forgot to do something here.

06:58.840 --> 07:00.610
We need to go here.

07:00.610 --> 07:06.160
Hit plus, drag settings over here and find UI settings.

07:06.160 --> 07:10.600
And we need to choose BGM slider value from the above over here.

07:10.960 --> 07:11.590
All right.

07:11.590 --> 07:19.150
And for the sound effects going to be the same let's drag settings and choose SFX Slider value.

07:19.150 --> 07:19.600
All right.

07:19.630 --> 07:20.590
Now it's going to work.

07:20.590 --> 07:21.880
Let's go to play mode.

07:23.540 --> 07:26.120
And you can see I'm dragging the slider.

07:26.120 --> 07:27.170
It works.

07:27.170 --> 07:29.930
It does affect the mixer over here.

07:31.280 --> 07:32.120
Yeah, sorry.

07:32.120 --> 07:35.240
So it does work and it does affect mixer over here.

07:35.240 --> 07:43.760
But the problem is it moves it only by one because BGM slider is from 0 to 1.

07:43.760 --> 07:44.960
And that's the issue.

07:44.960 --> 07:50.870
We need to somehow apply it here so it will be affected all the way down or all the way above.

07:50.870 --> 07:53.960
Because mixer itself has plus 20 -80.

07:53.990 --> 08:00.800
You could technically just set values over here -80 to 20, but that is not really a good way to do

08:00.800 --> 08:01.130
that.

08:01.130 --> 08:04.730
So we're going to go and make a multiplier for that.

08:05.590 --> 08:07.660
That will make it easier for us.

08:08.290 --> 08:11.320
Um, I'm going to make a serialized field.

08:11.320 --> 08:12.370
Private float.

08:14.660 --> 08:20.180
I'm going to do mixer multiplier equals to 25 by default.

08:20.180 --> 08:23.750
Then over here we're going to make float new value.

08:26.360 --> 08:27.950
He goes to math F.

08:29.010 --> 08:34.980
Log ten of value and we're going to multiply it by mixer multiplier.

08:35.220 --> 08:35.940
Just like that.

08:35.940 --> 08:38.730
And then over here we're going to use new value.

08:39.180 --> 08:40.140
Same goes here.

08:40.140 --> 08:43.290
We need to do it here I'm going to do float new value.

08:43.860 --> 08:47.220
Uh I guess I can just duplicate this line and move it here.

08:49.510 --> 08:53.200
And then we're going to pass new value here because of that.

08:53.200 --> 08:56.800
Now the slider will move much more.

08:56.800 --> 08:59.920
I would say okay, let's go ahead and try it.

09:02.390 --> 09:07.520
And now you can see I'm adjusting the slider and it goes way down like that.

09:07.550 --> 09:08.870
There is a bug.

09:08.870 --> 09:14.540
We can completely reduce the volume and it will snap back to zero.

09:15.940 --> 09:22.300
That happens because while you here can be zero, and when you multiply something by zero, it becomes

09:22.300 --> 09:22.840
zero.

09:22.840 --> 09:29.530
So to fix that, we need to select these both sliders and make minimum value as 0.01.

09:29.800 --> 09:31.630
Now it will never go to zero.

09:31.630 --> 09:34.480
If you make it minimum it's going to be minimum.

09:34.840 --> 09:35.770
Just like that.

09:37.140 --> 09:41.550
And now you can hear the music and you cannot hear the music.

09:46.240 --> 09:47.020
All right.

09:47.110 --> 09:48.490
This is very good.

09:48.520 --> 09:52.660
Now let's add the percentage so you can see percent.

09:52.660 --> 09:56.620
And we can just, you know just a bit of a polish here.

09:56.740 --> 09:58.750
And let's go to the slider.

09:59.080 --> 10:01.330
We're going to find the handle area.

10:01.540 --> 10:03.040
There is the handle.

10:03.040 --> 10:06.700
And I'm going to give it a child of a text mesh Pro.

10:07.910 --> 10:12.020
I'm going to just call it percentage suffix.

10:12.380 --> 10:18.200
And let's imagine this one says 46%, just that we're going to align it to the center.

10:18.200 --> 10:21.800
I guess we probably should change the font to what we usually have.

10:22.100 --> 10:24.980
And now we're going to move it below like that.

10:26.350 --> 10:27.190
Just like that.

10:27.620 --> 10:28.580
Very cool.

10:28.610 --> 10:30.410
Now let's duplicate it.

10:30.440 --> 10:33.320
Let's move it to.

10:36.320 --> 10:38.540
Let's make it as a child of a handle over here.

10:38.540 --> 10:40.940
We're going to change it to BGM.

10:40.940 --> 10:41.660
We're going to.

10:42.570 --> 10:45.990
Line it in the center and then move it down like that as well.

10:46.470 --> 10:50.640
We can't really see it because of the character here, but I think it's okay.

10:50.640 --> 10:51.420
It doesn't matter.

10:51.420 --> 10:57.330
You can just move character or you can raise up the entire slider like that.

10:58.360 --> 11:00.130
All right, not a problem.

11:00.340 --> 11:00.850
Cool.

11:00.850 --> 11:02.140
So now we have this text.

11:02.140 --> 11:03.250
Let's go to settings.

11:03.250 --> 11:12.850
And let's assign this text by just dragging these two percentage BGM and this one to as a fix okay nice

11:12.850 --> 11:13.720
I like it.

11:15.620 --> 11:18.920
What I don't like though is that we have a suffix BGM.

11:18.950 --> 11:23.000
We have a suffix BGM, but in the hierarchy it's the opposite.

11:23.000 --> 11:26.510
I hate it, so I'm going to just place it above like that.

11:26.510 --> 11:27.230
All right.

11:27.230 --> 11:27.980
Cool.

11:27.980 --> 11:30.110
So we did assign text over here.

11:30.110 --> 11:33.920
We can go back and we can do something like this.

11:38.540 --> 11:40.850
We can do a suffix slider.

11:42.780 --> 11:46.080
Text dot text equals to mathbf.

11:46.110 --> 11:47.820
We're going to round up the number we have.

11:47.820 --> 11:49.650
So I'm going to do round to int.

11:49.650 --> 11:50.730
And we're going to give it value.

11:50.730 --> 11:55.260
And we're going to multiply it by 100 because slider's value can be from 0 to 1.

11:55.260 --> 12:00.000
And if you multiply it by 100 it's going to be like person like you know, 100 or 1.

12:00.000 --> 12:03.360
So I'm going to do plus here percentage sign.

12:03.360 --> 12:05.340
Thanks to that we're going to have a nice text.

12:05.340 --> 12:12.090
We only need to go here paste it in and replace it with the background slider text.

12:15.220 --> 12:17.920
Okay, we almost done here?

12:17.920 --> 12:19.600
It is almost perfect.

12:19.600 --> 12:24.760
We only need to save the settings every time we close them up, or every time we open the settings.

12:24.760 --> 12:26.470
We need to load up the settings.

12:26.470 --> 12:32.290
Because as of now, even if you change something and you can see new percentage value, it does not

12:32.290 --> 12:37.870
affect your game when you go further, like when you exit the game and play the game again, you would

12:37.870 --> 12:39.940
have to change settings again.

12:39.940 --> 12:45.550
That's not what we need and because of that, we're going to go here and we're going to make on disable

12:45.550 --> 12:49.390
method on disable is called every time you disable the game object.

12:49.390 --> 12:51.880
So this is just the perfect option for us.

12:51.880 --> 12:55.210
We're going to take Playerprefs set float.

12:55.210 --> 13:02.110
And we just can use as a fixed parameter easy for us and give it as a fixed slider value.

13:02.110 --> 13:09.970
Then same goes for Playerprefs set float of BGM parameter and we're going to give it BGM slider value

13:10.210 --> 13:10.750
right?

13:10.750 --> 13:11.800
This is very good.

13:13.190 --> 13:15.350
Also, we're gonna load up the settings.

13:15.350 --> 13:20.930
But for some reason when I did test this on, enable did not work very well.

13:20.960 --> 13:24.530
I'm not sure why, I'm just going to try it now if it will not work.

13:24.530 --> 13:26.660
I have a way around of that.

13:26.660 --> 13:29.510
Okay, so let me copy these two.

13:29.720 --> 13:31.400
Paste them in here.

13:32.340 --> 13:41.340
And then I'm going to do a suffixed slider dot value equals to playerprefs get float of a suffixed parameter,

13:41.340 --> 13:45.270
and by default I want to give it maybe 0.7 f.

13:45.270 --> 13:48.060
So it's not very loud, just 70% of that.

13:48.330 --> 13:53.640
Then we're going to do BGM slider dot value equals to playerprefs.

13:54.670 --> 13:55.690
Getfloat.

13:57.510 --> 14:01.740
And again I'm going to do 0.7 by default if you don't have anything set before.

14:02.250 --> 14:03.840
So I'm going to save this.

14:03.840 --> 14:04.710
I'm going to double check.

14:04.710 --> 14:08.550
But again for some reason on enable did not work last time.

14:09.090 --> 14:10.110
Let me try.

14:13.540 --> 14:15.580
Oh, it works okay.

14:16.000 --> 14:18.070
Then we have even less work to do.

14:18.730 --> 14:21.070
Back settings.

14:21.850 --> 14:22.810
Cool.

14:22.840 --> 14:25.690
Now let me just mute the game.

14:25.690 --> 14:26.860
Going to go to play mode.

14:26.860 --> 14:27.910
If I'm not mistaken.

14:27.910 --> 14:30.730
It's supposed to be like 19 and yes.

14:30.730 --> 14:32.020
All right.

14:32.020 --> 14:35.020
This is just amazing man I love it so much.

14:35.170 --> 14:37.210
All right, settings are done.

14:37.630 --> 14:40.090
Now we can go to the next video.

14:40.630 --> 14:41.470
I'll see you there.
