AudioListener.volume doesn't work

I know it’s been many times here but I still can’t find the solution. I’ve checked the usual suspects. But first things first - I have a scene, some objects in it, including AudioSource’s, and one AudioListener attached to the main camera. I want to mute all sounds after clicking the button with the following code (I hope it’s self-explanatory):

AudioListener.volume = GameState.sound ? 1.0f : 0.0f;

But the sounds still play (music too). Usual suspects: more than 1 AudioListener (checked, I have only 1), AudioSource’s have ignoreListenerVolume set to true (also not the case).

Interestingly enough, AudioListener.pause works, but that’s not what I need.

I’ve checked in the debugger the quoted line of code and AudioListener.volume is always 1 before the execution of that line. So it somehow resets itself but I don’t know how.

Any ideas, please?

Either GameState.sound returns true where you expect it to return false, or you are writing to AudioListener.volume elsewhere?

using UnityEngine;
using System.Collections;

public class Test : MonoBehaviour {
	void OnGUI() {
		GUILayout.Label (AudioListener.volume.ToString());
		if (GUILayout.Button("Mute"))
			AudioListener.volume = 0;
		if (GUILayout.Button("Play"))
			AudioListener.volume = 1;
	}
}

I tried this and it seems to behave as expected.

Nevermind, I found the reason. The guilty one is… Orthello2D. Specifically OTSounds.cs which for some reason overwrites AudioListener.volume each Update(). :stuck_out_tongue: I’ve search whole solution for AudioListener.volume and found it, I feel silly not to have thought of that earlier. Thx for help, though.