1
00:00:00,000 --> 00:00:00,000
Hello, guys.

2
00:00:00,000 --> 00:00:03,000
In this video, I want to make settings of the UI work.

3
00:00:03,000 --> 00:00:07,000
We're going to make an audio mixer that controls volume of sound effects and background music.

4
00:00:07,000 --> 00:00:11,000
And then we're going to make that sliders in the settings, going to control that parameters.

5
00:00:12,000 --> 00:00:16,000
And regarding those buttons of the day night system, we're going to do it later.

6
00:00:16,000 --> 00:00:21,000
Once we have that system in the game, don't think about these three buttons now.

7
00:00:21,000 --> 00:00:23,000
Let's just take care of these two sliders over here.

8
00:00:23,000 --> 00:00:26,000
So what I'm going to do is go to window.

9
00:00:27,000 --> 00:00:31,000
Audio audio mixer and now I have mixer in the game.

10
00:00:31,000 --> 00:00:33,000
I want to drag it over here to the top.

11
00:00:34,000 --> 00:00:36,000
And if we hit plus over here.

12
00:00:37,000 --> 00:00:40,000
We can create audio mixer.

13
00:00:41,000 --> 00:00:45,000
Now, under this audio mixer, we can create groups for different sounds.

14
00:00:45,000 --> 00:00:47,000
We can do that by clicking plus over here.

15
00:00:47,000 --> 00:00:49,000
And first on alcohol.

16
00:00:49,000 --> 00:00:50,000
Background.

17
00:00:51,000 --> 00:00:52,000
Music.

18
00:00:53,000 --> 00:00:55,000
Now let's select, muster and click one more.

19
00:00:55,000 --> 00:00:59,000
Plus, there's going to be sound effects.

20
00:00:59,000 --> 00:00:59,000
All right.

21
00:00:59,000 --> 00:01:04,000
So with the help of these two sliders, we can control sound effects and background volume.

22
00:01:04,000 --> 00:01:06,000
Let's choose sound effects.

23
00:01:09,000 --> 00:01:12,000
Click output and choose sound effects here.

24
00:01:12,000 --> 00:01:13,000
And same for the background music.

25
00:01:13,000 --> 00:01:16,000
And for background music, we're going to choose output.

26
00:01:17,000 --> 00:01:18,000
Background music.

27
00:01:18,000 --> 00:01:21,000
Now I want to go to play mode and show you how does it work.

28
00:01:21,000 --> 00:01:23,000
We have music playing in the game.

29
00:01:24,000 --> 00:01:26,000
Now I want to show you how does it work?

30
00:01:26,000 --> 00:01:28,000
I'm going to click edit in the play mode.

31
00:01:28,000 --> 00:01:33,000
And if I drag the slider, you can hear my volume of the background.

32
00:01:33,000 --> 00:01:40,000
Music is lower if I drag it into the maximum, it was much louder.

33
00:01:40,000 --> 00:01:40,000
Right?

34
00:01:40,000 --> 00:01:43,000
And we're going to control these two sliders.

35
00:01:43,000 --> 00:01:44,000
Let me set it back to zero.

36
00:01:45,000 --> 00:01:50,000
Yeah, we're going to control these two sliders with the help of sliders in the settings.

37
00:01:52,000 --> 00:01:53,000
Where is it?

38
00:01:54,000 --> 00:01:55,000
Here.

39
00:01:56,000 --> 00:02:04,000
So basically, I'm going to take this value of this slider and pass it to the slider of the mixer.

40
00:02:04,000 --> 00:02:05,000
All right.

41
00:02:05,000 --> 00:02:07,000
Let's create a script first.

42
00:02:07,000 --> 00:02:10,000
It's going to be pretty simple Script UI.

43
00:02:11,000 --> 00:02:13,000
Uh, volume.

44
00:02:14,000 --> 00:02:15,000
Slider.

45
00:02:17,000 --> 00:02:19,000
Let's create serialized field.

46
00:02:19,000 --> 00:02:20,000
First we need a slider.

47
00:02:20,000 --> 00:02:22,000
So private slider.

48
00:02:23,000 --> 00:02:25,000
And I'm going to call it just slider.

49
00:02:27,000 --> 00:02:34,000
Then serialize field private audio mixer and I'm going to call it just audio mixer.

50
00:02:34,000 --> 00:02:40,000
Now if you remember, we had different groups, one for background music, one for sound effects.

51
00:02:40,000 --> 00:02:43,000
So we need kind of a parameter that you're going to access.

52
00:02:43,000 --> 00:02:46,000
So I'm going to do serialize field, private string.

53
00:02:48,000 --> 00:02:50,000
Ideal parameter.

54
00:02:52,000 --> 00:02:58,000
Now let's go below that and create private void on value changed.

55
00:02:58,000 --> 00:03:05,000
We're going to pass a float value and inside we're going to change value of the mixer with the certain

56
00:03:05,000 --> 00:03:05,000
parameter.

57
00:03:05,000 --> 00:03:07,000
So we're going to do an audio mixer.

58
00:03:09,000 --> 00:03:11,000
Said float and then said, You can see we need a name.

59
00:03:11,000 --> 00:03:16,000
So our parameter and as a value, we're going to just pass value, then we're going to make an awake

60
00:03:16,000 --> 00:03:17,000
function.

61
00:03:17,000 --> 00:03:22,000
And we did something like this with the buttons before just now, instead of button, it is a slider,

62
00:03:22,000 --> 00:03:29,000
so we're going to do slider on value changed add listener and we're going to pass function on value

63
00:03:29,000 --> 00:03:29,000
changed.

64
00:03:30,000 --> 00:03:33,000
You know, I kind of don't like to have same name.

65
00:03:33,000 --> 00:03:35,000
So let's change this to slider value.

66
00:03:36,000 --> 00:03:37,000
Slider value.

67
00:03:37,000 --> 00:03:38,000
This looks better.

68
00:03:38,000 --> 00:03:41,000
Now, before we continue, I want to make sure all of this is working.

69
00:03:41,000 --> 00:03:43,000
So let's go back to Unity.

70
00:03:44,000 --> 00:03:50,000
You're going to take slider of the we're going to take slider of the sound track the script.

71
00:03:50,000 --> 00:03:51,000
We're going to.

72
00:03:52,000 --> 00:03:54,000
A sign slider itself.

73
00:03:57,000 --> 00:04:02,000
We're going to assign our mixer, we can just click over here and it's going to be there and we need

74
00:04:02,000 --> 00:04:03,000
our parameter.

75
00:04:03,000 --> 00:04:05,000
How do we make the parameter?

76
00:04:05,000 --> 00:04:06,000
Very simple.

77
00:04:06,000 --> 00:04:11,000
We're going to go to our audio mixer and this one for sounds, right?

78
00:04:11,000 --> 00:04:12,000
So let's choose Sound Effect.

79
00:04:12,000 --> 00:04:18,000
Then we're going to go here to volume, click right button and choose expose volume.

80
00:04:18,000 --> 00:04:27,000
Then here we can click my expose parameter, click twice for change a name, and we're going to change

81
00:04:27,000 --> 00:04:28,000
it to just as a fix.

82
00:04:29,000 --> 00:04:30,000
Now let's do the same for background music.

83
00:04:30,000 --> 00:04:36,000
While we're here, you're going to select background music, expose volume, change the name.

84
00:04:37,000 --> 00:04:38,000
BGM.

85
00:04:38,000 --> 00:04:40,000
Now we know names of those.

86
00:04:40,000 --> 00:04:43,000
We can go back to Slider and type here just as a fix.

87
00:04:45,000 --> 00:04:48,000
Now let's set up background music slider as well.

88
00:04:48,000 --> 00:04:52,000
We're going to drag the script from the script folder UI.

89
00:04:53,000 --> 00:05:02,000
Here in this volume slider lets assign slider itself order mixer and parameter BGM.

90
00:05:04,000 --> 00:05:05,000
Good enough.

91
00:05:05,000 --> 00:05:07,000
Now let's go to play mode and see how does it work?

92
00:05:07,000 --> 00:05:11,000
Look, I'm going to settings and I'm going to select Slider so I can see it.

93
00:05:11,000 --> 00:05:13,000
Here it is for the music.

94
00:05:14,000 --> 00:05:16,000
I can drag this one.

95
00:05:16,000 --> 00:05:19,000
I can see my value getting changed in the inspector.

96
00:05:20,000 --> 00:05:27,000
But the problem is the values in the background music slider is really high, like there is values from

97
00:05:27,000 --> 00:05:28,000
-80 up to 20.

98
00:05:28,000 --> 00:05:32,000
And if I drag this one, it does change this only from 0 to 1.

99
00:05:32,000 --> 00:05:34,000
So we need to make a multiplier.

100
00:05:34,000 --> 00:05:39,000
Sorry, maybe music was too loud so we need to make a multiplier for that.

101
00:05:39,000 --> 00:05:42,000
So while you're going to be changed accordingly.

102
00:05:43,000 --> 00:05:44,000
Let's go and do that.

103
00:05:44,000 --> 00:05:46,000
It's not going to be very difficult.

104
00:05:46,000 --> 00:05:52,000
We're just going to make serialize field, private, float multiplier.

105
00:05:52,000 --> 00:05:55,000
And I want to set default value to something like 25.

106
00:05:58,000 --> 00:06:00,000
Now inside instead of value.

107
00:06:00,000 --> 00:06:02,000
I want to type math f.

108
00:06:02,000 --> 00:06:10,000
Dot log ten and now we can give it a parameter value multiplied by multiplier.

109
00:06:11,000 --> 00:06:13,000
And I think I forgot the parentheses.

110
00:06:13,000 --> 00:06:14,000
Yeah, like that.

111
00:06:17,000 --> 00:06:20,000
Now, while we are here, let's make sure we saving that value.

112
00:06:20,000 --> 00:06:23,000
Once we exit in the settings, it's going to be pretty easy task.

113
00:06:23,000 --> 00:06:29,000
We're going to use on disabled function, which is called when you disable and object on disable.

114
00:06:29,000 --> 00:06:37,000
And here we're going to do player press set float of our parameter to.

115
00:06:39,000 --> 00:06:41,000
Slider dot value.

116
00:06:41,000 --> 00:06:42,000
Pretty simple.

117
00:06:44,000 --> 00:06:47,000
If you want to upload this value, it's going to be easy as well.

118
00:06:47,000 --> 00:06:49,000
We're just going to do slider value.

119
00:06:51,000 --> 00:06:53,000
Equals to their preps.

120
00:06:55,000 --> 00:06:59,000
Get float of audio parameter.

121
00:06:59,000 --> 00:07:01,000
And just in case nothing is saved, we can pass it.

122
00:07:01,000 --> 00:07:08,000
A default value and default value will be the one we set in the inspector Just slider value itself.

123
00:07:08,000 --> 00:07:10,000
Let's save it all and go back to unity.

124
00:07:10,000 --> 00:07:15,000
I'm going to choose my tool sliders and give them default value of point six.

125
00:07:19,000 --> 00:07:20,000
Point six.

126
00:07:22,000 --> 00:07:26,000
Now we can see we go to settings and our slider is at 0.6.

127
00:07:26,000 --> 00:07:29,000
If I drag it to the minimum, the volume is much lower.

128
00:07:29,000 --> 00:07:32,000
If I drag it to the maximum, volume is just like we need.

129
00:07:38,000 --> 00:07:41,000
There is a couple of more issues we need to fix.

130
00:07:41,000 --> 00:07:47,000
The first one, if I drag my slider all the way to the minimum, it's going to snap to default value.

131
00:07:49,000 --> 00:07:56,000
You can see even the slider is at minimum the value is zero now because actual value is zero.

132
00:07:56,000 --> 00:07:59,000
And then we pass in zero over here.

133
00:07:59,000 --> 00:08:02,000
What we can do is to make a slight fix.

134
00:08:02,000 --> 00:08:07,000
Back in the code, we just want to set minimum value of the slider and that is pretty easy.

135
00:08:07,000 --> 00:08:12,000
Slider mean value equals 2.0 01f.

136
00:08:13,000 --> 00:08:14,000
Yeah, we done here.

137
00:08:14,000 --> 00:08:16,000
There is last issue.

138
00:08:16,000 --> 00:08:19,000
As I told you, there are still issues we need to fix.

139
00:08:19,000 --> 00:08:27,000
And this is the last one at the moment we upload in values of the slider in the volume slider away function,

140
00:08:27,000 --> 00:08:31,000
but this function is not called until you switch to settings itself.

141
00:08:31,000 --> 00:08:33,000
So now in the main menu.

142
00:08:35,000 --> 00:08:39,000
Yeah, you can see while you are at zero and if I click settings, then they're going to be changed

143
00:08:39,000 --> 00:08:41,000
to the one we used last time.

144
00:08:41,000 --> 00:08:45,000
So what I want to do here is to load this value from the UI main script.

145
00:08:45,000 --> 00:08:46,000
How are we going to do that?

146
00:08:46,000 --> 00:08:48,000
Pretty simple, actually.

147
00:08:48,000 --> 00:08:53,000
We're just going to wrap this up in the function, so let's select all of three lines, Click alt,

148
00:08:53,000 --> 00:08:55,000
enter, extract method.

149
00:08:56,000 --> 00:09:00,000
It's going to be named as set top slider.

150
00:09:01,000 --> 00:09:02,000
I don't need to work now.

151
00:09:02,000 --> 00:09:03,000
I can delete it.

152
00:09:03,000 --> 00:09:05,000
And I want to make this function public.

153
00:09:08,000 --> 00:09:12,000
Now you I mean, we're going back to you, I mean, and creating a header.

154
00:09:13,000 --> 00:09:16,000
Volume sliders.

155
00:09:17,000 --> 00:09:19,000
Let's create an array of the volume slider script.

156
00:09:19,000 --> 00:09:25,000
So serialize field, private UI volume, slider and array.

157
00:09:26,000 --> 00:09:27,000
Slider.

158
00:09:29,000 --> 00:09:29,000
It's like there is so.

159
00:09:31,000 --> 00:09:31,000
Yeah.

160
00:09:32,000 --> 00:09:35,000
And in the start function, I want to make a short for loop.

161
00:09:36,000 --> 00:09:38,000
We're going to do it as long as we have sliders.

162
00:09:38,000 --> 00:09:42,000
So sliders dot lengths and inside below the sliders.

163
00:09:43,000 --> 00:09:48,000
When I say sliders, I think of the whole small cheeseburgers or something like that.

164
00:09:50,000 --> 00:09:51,000
Really funny.

165
00:09:51,000 --> 00:09:51,000
Let me.

166
00:09:52,000 --> 00:09:54,000
Let me change this to a slider.

167
00:09:54,000 --> 00:09:54,000
I'm sorry.

168
00:09:55,000 --> 00:09:56,000
Sorry.

169
00:09:56,000 --> 00:10:00,000
It took me some time to come down, So we need to pass an eye here.

170
00:10:01,000 --> 00:10:02,000
Slider, I.

171
00:10:02,000 --> 00:10:03,000
Dot.

172
00:10:04,000 --> 00:10:05,000
Set up slide there.

173
00:10:06,000 --> 00:10:06,000
Very good.

174
00:10:06,000 --> 00:10:08,000
Now let's go back to Unity.

175
00:10:08,000 --> 00:10:13,000
Let's select our canvas and drag sliders to slider array.

176
00:10:13,000 --> 00:10:16,000
One, two.

177
00:10:17,000 --> 00:10:18,000
We have it there.

178
00:10:18,000 --> 00:10:19,000
All right.

179
00:10:20,000 --> 00:10:26,000
Now we can see that mixer was set at the beginning, even in the main menu before we clicked settings.

180
00:10:29,000 --> 00:10:30,000
We can change them.

181
00:10:31,000 --> 00:10:32,000
Close it.

182
00:10:32,000 --> 00:10:35,000
Exit the play mode and once we enter it again.

183
00:10:38,000 --> 00:10:39,000
Information is saved.

184
00:10:39,000 --> 00:10:40,000
Perfect.

185
00:10:40,000 --> 00:10:42,000
Let's jump to next video.

