- Home /
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?
Answer by NPS · Jul 16, 2013 at 04:53 PM
Nevermind, I found the reason. The guilty one is... Orthello2D. Specifically OTSounds.cs
which for some reason overwrites AudioListener.volume
each Update()
. :P 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.
Answer by Statement · Jul 16, 2013 at 02:53 PM
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.
GameState.sound
returns values I expect (checked). For the other possibility - do you mean Audio*Listener or AudioSource*? Edit: I've found the solution but I would still like you to answer.
Of course I meant Audio*Listener*.volume, thanks for pointing that out :)
Your answer
Follow this Question
Related Questions
sound too low in Android devices 0 Answers
[Not Fixed] Music doesent mute, please help 1 Answer
AudioListener (v4.6) missing volume 1 Answer