Audio Source will not "unmute" after toggling?

Hello,

I’ve been working at this for 2 days and I’ve had some great help, but it seems like something isn’t working right. I am using this script to toggle the mute parameter on an Audio Source:

// Mutes-Unmutes the sound of this transfor each time the user presses escape.

	function Update() {
		 if(Input.GetKeyDown(KeyCode.Escape)) {
		 	if(audio.mute)
				audio.mute = false;
			else
				audio.mute = true;
		}
	}

This script works perfectly for muting the audio source, but it doesn’t seem to unmute the audio. Basically, if I start the scene with the mute button ticked on the audio source, it will not unmute the audio source and toggle the mute button each time I press escape. The check-mark on the mute parameter stays ticked on the audio source and no audio plays. If anybody could please help me out on this one, I would really appreciate it! Trust me, I’ve spent a ton of time on this one, and I just can’t figure it out! THANK YOU SO MUCH for your help!!

This script i made is rather crude. Currently, i can’t test any script myself so i made it a simple one for you.

Replace if(audio.mute) and beyond with:

if(audio.mute == false){
MuteAudio();
}else{
Unmute();
}

function MuteAudio(){
yield WaitForSeconds(0.01);
audio.mute = true;
}

function UnmuteAudio(){
yield WaitForSeconds(0.01);
audio.mute = false;
}

Hopfully the script works. Hope this helps!

Add this script below to the audio source, then drag the audio source itself into the public variable on the script component, then drag the audio source into the ‘On Click()’ part of the button. The button will then toggle the ‘mute’ button on the audio source.

public AudioSource appMusic;

public void MusicMute()
{
    appMusic.mute = !appMusic.mute;
}