1
00:00:00,000 --> 00:00:00,000
Hello, guys.

2
00:00:00,000 --> 00:00:03,000
In this video, we're going to take care of the mute button we have here.

3
00:00:03,000 --> 00:00:09,000
It's going to be a pretty simple task, very short couple of lines of code and also very easy to understand.

4
00:00:09,000 --> 00:00:10,000
How does it work?

5
00:00:10,000 --> 00:00:12,000
So let's go to your main.

6
00:00:13,000 --> 00:00:18,000
We need to go above over here and I want to create boolean that says muted.

7
00:00:18,000 --> 00:00:21,000
So private ball game muted.

8
00:00:21,000 --> 00:00:24,000
Now let's go and create a button function.

9
00:00:24,000 --> 00:00:33,000
Somewhere here is OC public void mute button inside we need to switch boolean first we're going to do

10
00:00:33,000 --> 00:00:38,000
game muted equals to not game muted and I know this statement can be a bit confusing.

11
00:00:38,000 --> 00:00:43,000
It was very confusing for me at first, but basically it works like a switcher.

12
00:00:43,000 --> 00:00:44,000
I'm going to put a comment here.

13
00:00:44,000 --> 00:00:46,000
Works like a switcher.

14
00:00:46,000 --> 00:00:48,000
So what's the point of this?

15
00:00:48,000 --> 00:00:55,000
Basically, if game muted is false, we're going to set it to an opposite value, which is true.

16
00:00:55,000 --> 00:01:00,000
If muted is true, we're going to set it to opposite value, which is false and that's it.

17
00:01:00,000 --> 00:01:02,000
So it's kind of just switching between false and true all the time.

18
00:01:03,000 --> 00:01:06,000
Then we're going to do simple if statement if a muted.

19
00:01:07,000 --> 00:01:14,000
Then I'll do listener dot volume equals to zero else.

20
00:01:15,000 --> 00:01:19,000
We're going to do our listener volume equals to one.

21
00:01:20,000 --> 00:01:21,000
And that's it.

22
00:01:21,000 --> 00:01:23,000
Let's go back to Unity.

23
00:01:24,000 --> 00:01:26,000
I'm going to find my mute buttons.

24
00:01:26,000 --> 00:01:28,000
We have two mute buttons, if you remember.

25
00:01:29,000 --> 00:01:33,000
We have one in the main menu and one in the in game UI.

26
00:01:33,000 --> 00:01:35,000
So let's select them both.

27
00:01:35,000 --> 00:01:40,000
Click plus icon, drag the canvas and find the mute button function.

28
00:01:42,000 --> 00:01:42,000
All right.

29
00:01:42,000 --> 00:01:44,000
First, let's go and make sure it's working.

30
00:01:45,000 --> 00:01:50,000
You see, volume is appearing and disappearing when I'm pressing that space key, which is not right.

31
00:01:50,000 --> 00:01:51,000
The fix that.

32
00:01:52,000 --> 00:01:55,000
We're going to go to navigation over here and click none.

33
00:01:56,000 --> 00:01:56,000
All right.

34
00:01:56,000 --> 00:01:57,000
That solves the issue.

35
00:01:57,000 --> 00:02:03,000
And second one, I want to make this icon transparent when game is muted so it's clear what is happening

36
00:02:03,000 --> 00:02:04,000
there.

37
00:02:04,000 --> 00:02:10,000
Let's go back to code and somewhere above, I want to create a header.

38
00:02:10,000 --> 00:02:12,000
Maybe we can use this header over here.

39
00:02:12,000 --> 00:02:19,000
I'm just going to change this from sliders to volume info and we're going to create serialize field,

40
00:02:19,000 --> 00:02:22,000
private image, mute icon.

41
00:02:23,000 --> 00:02:24,000
So there's going to be a mute icon.

42
00:02:24,000 --> 00:02:25,000
We're going to change.

43
00:02:25,000 --> 00:02:31,000
And if you remember, we have two mute icons, one in the main menu, one in the in-game menu.

44
00:02:32,000 --> 00:02:39,000
So once we start the game, we want to assign mute icon to new icon, the one that is in the game.

45
00:02:39,000 --> 00:02:42,000
So let's do serialize field private image.

46
00:02:43,000 --> 00:02:46,000
In-game mute icon.

47
00:02:47,000 --> 00:02:52,000
First, let's assign an icon to a new one, and we can do that in the Start game button.

48
00:02:52,000 --> 00:03:01,000
So let's make this function with the curly brackets and type mute icon equals to game mute icon.

49
00:03:02,000 --> 00:03:03,000
Very good.

50
00:03:03,000 --> 00:03:07,000
Now, in the mute button itself, we need to make a transparent color.

51
00:03:07,000 --> 00:03:08,000
So color.

52
00:03:10,000 --> 00:03:11,000
Mute.

53
00:03:11,000 --> 00:03:14,000
Color equals to new color.

54
00:03:14,000 --> 00:03:20,000
Which is going to be 111 and point five F to make it transparent.

55
00:03:21,000 --> 00:03:27,000
Then when game is muted, we're going to take mute icon dot color and set it to mute color.

56
00:03:27,000 --> 00:03:30,000
And when game is not muted, we're going to take mute icon.

57
00:03:32,000 --> 00:03:40,000
That color and set it to color dot white, because color white has just 1111 on all of the parameters.

58
00:03:41,000 --> 00:03:43,000
And that's it for the functionality.

59
00:03:43,000 --> 00:03:44,000
Let's go and see this.

60
00:03:46,000 --> 00:03:49,000
We need to select canvas and drag icons.

61
00:03:49,000 --> 00:03:55,000
So mute icon and in-game mute icon now in the play mode.

62
00:03:58,000 --> 00:03:59,000
We can see this.

63
00:04:00,000 --> 00:04:01,000
It's getting darker.

64
00:04:02,000 --> 00:04:03,000
Let's try in the game.

65
00:04:11,000 --> 00:04:12,000
Now we need to check the last one.

66
00:04:12,000 --> 00:04:15,000
What's going to happen if I mute game in the main menu?

67
00:04:15,000 --> 00:04:16,000
And then I clicked up the start?

68
00:04:24,000 --> 00:04:28,000
So game is muted, but color wasn't changed.

69
00:04:28,000 --> 00:04:30,000
But it is changed now.

70
00:04:30,000 --> 00:04:32,000
We can fix that back.

71
00:04:32,000 --> 00:04:33,000
Pretty simple to do.

72
00:04:34,000 --> 00:04:35,000
Just in the game.

73
00:04:35,000 --> 00:04:36,000
Start.

74
00:04:36,000 --> 00:04:37,000
Let's do this.

75
00:04:41,000 --> 00:04:42,000
If.

76
00:04:44,000 --> 00:04:46,000
Game muted then mute.

77
00:04:46,000 --> 00:04:47,000
I can.

78
00:04:49,000 --> 00:04:51,000
Color equals to.

79
00:04:52,000 --> 00:04:56,000
And let's take this over here and put it here.

80
00:04:58,000 --> 00:05:05,000
And maybe we can actually save one line of code and just place it here like that and delete this one

81
00:05:05,000 --> 00:05:06,000
from here.

82
00:05:06,000 --> 00:05:07,000
Yeah.

83
00:05:07,000 --> 00:05:08,000
Doesn't make a big difference, Right?

84
00:05:09,000 --> 00:05:12,000
Then go and make sure it's working.

85
00:05:14,000 --> 00:05:19,000
So it's muted tap to start still muted and then and mute.

86
00:05:20,000 --> 00:05:21,000
Perfect.

87
00:05:21,000 --> 00:05:23,000
I'll see you in the next video.

