Hello, guys.
In this video, we're going to take care of the mute button we have here.
It's going to be a pretty simple task, very short couple of lines of code and also very easy to understand.
How does it work?
So let's go to your main.
We need to go above over here and I want to create boolean that says muted.
So private ball game muted.
Now let's go and create a button function.
Somewhere here is OC public void mute button inside we need to switch boolean first we're going to do
game muted equals to not game muted and I know this statement can be a bit confusing.
It was very confusing for me at first, but basically it works like a switcher.
I'm going to put a comment here.
Works like a switcher.
So what's the point of this?
Basically, if game muted is false, we're going to set it to an opposite value, which is true.
If muted is true, we're going to set it to opposite value, which is false and that's it.
So it's kind of just switching between false and true all the time.
Then we're going to do simple if statement if a muted.
Then I'll do listener dot volume equals to zero else.
We're going to do our listener volume equals to one.
And that's it.
Let's go back to Unity.
I'm going to find my mute buttons.
We have two mute buttons, if you remember.
We have one in the main menu and one in the in game UI.
So let's select them both.
Click plus icon, drag the canvas and find the mute button function.
All right.
First, let's go and make sure it's working.
You see, volume is appearing and disappearing when I'm pressing that space key, which is not right.
The fix that.
We're going to go to navigation over here and click none.
All right.
That solves the issue.
And second one, I want to make this icon transparent when game is muted so it's clear what is happening
there.
Let's go back to code and somewhere above, I want to create a header.
Maybe we can use this header over here.
I'm just going to change this from sliders to volume info and we're going to create serialize field,
private image, mute icon.
So there's going to be a mute icon.
We're going to change.
And if you remember, we have two mute icons, one in the main menu, one in the in-game menu.
So once we start the game, we want to assign mute icon to new icon, the one that is in the game.
So let's do serialize field private image.
In-game mute icon.
First, let's assign an icon to a new one, and we can do that in the Start game button.
So let's make this function with the curly brackets and type mute icon equals to game mute icon.
Very good.
Now, in the mute button itself, we need to make a transparent color.
So color.
Mute.
Color equals to new color.
Which is going to be 111 and point five F to make it transparent.
Then when game is muted, we're going to take mute icon dot color and set it to mute color.
And when game is not muted, we're going to take mute icon.
That color and set it to color dot white, because color white has just 1111 on all of the parameters.
And that's it for the functionality.
Let's go and see this.
We need to select canvas and drag icons.
So mute icon and in-game mute icon now in the play mode.
We can see this.
It's getting darker.
Let's try in the game.
Now we need to check the last one.
What's going to happen if I mute game in the main menu?
And then I clicked up the start?
So game is muted, but color wasn't changed.
But it is changed now.
We can fix that back.
Pretty simple to do.
Just in the game.
Start.
Let's do this.
If.
Game muted then mute.
I can.
Color equals to.
And let's take this over here and put it here.
And maybe we can actually save one line of code and just place it here like that and delete this one
from here.
Yeah.
Doesn't make a big difference, Right?
Then go and make sure it's working.
So it's muted tap to start still muted and then and mute.
Perfect.
I'll see you in the next video.