Mute/Unmute not working with new sounds

I know here were several questions about mute-buttons and I could somehow use the answers here. However it’s not working in a way I expected it to. When i click my mute-button all active sounds turn silent (which is good!) but alltough the AudioListener is paused, newly instantiated audioSources are hearable. When I unmute and mute again they turn silent, too, but I want a mute-button that keeps everything quiet all the time.

private Rect _buttonRect = new Rect(10, 10, 100, 50);

void OnGUI()
{
	if(GUI.Button(_buttonRect, "Sound On/Off"))
	{
		AudioListener.pause = !AudioListener.pause;
	}
}

Did I make a mistake, or is this a bug?

Instead of pausing them, you could do `AudioListener.volume = 0.0F;` That would make all of the sounds at 0 volume, although I'm pretty sure that they would still play in the background, although the script reference (http://unity3d.com/support/documentation/ScriptReference/AudioListener-pause.html) for `AudioListener.pause` says that its the same as setting the volume to 0.

Try this script in replace of your current one, it's a bit of a modification:

This is the first time I have really ever programmed in C#!!!!!!!!!!!, at first it didn't work, but that was only because of the variable type, it had to be type 'bool', and I didn't specify the type. But after I realised it didn't work, I wrote it in JavaScript for you, so now you got both!!!

C#:

public bool muted = false;

void OnGUI()
{
    if (GUI.Button(new Rect(10, 10, 100, 50), "Sound On/Off"))
    {
       if(muted == false){
          AudioListener.volume = 0.0F;
          muted = true;
          }
       else{
          AudioListener.volume = 1.0F;
          muted = false;
          }
    }
}

JAVASCRIPT:

var muted = false;

function OnGUI(){

    if(GUI.Button(new Rect(10, 10, 100, 50), "Sound On/Off"))
    {
        if(muted == false){
        AudioListener.volume = 0;
        muted = true;
        }
        else{
        AudioListener.volume = 1;
        muted = false;
        }
    }
}

Hope this helps

Comment back if you need more help!!!!

-Grady

I agree they should change the manual for AudioListener.pause. It is not the same as setting AudioListener.volume = 0f for the exact reasons outlined above (NEW sounds don’t get set to zero). This is confusing and definitely wasted me some time.