Is it possible to change Audio Manager Volume by script?

Hi!

It happens that I have two audio Listeners in my scene (with one enabled when the other is disabled). I found out that no matter which Listener is enabled, if I would change the value in Audio Manager Settings (project settings, it will affect the overall volume. Well, is it possible to change that by script?

I know that I could achieve the same result by getting all the listener components (or the one currently enabled) and change their volume value. But except of that would be slightly more complicated, isn’t it more efficient to approach it from the shortcut way I look for?

Thank you!

I was afterwards looking to what is called singleton pattern. I guess, it would be useful to understand the concept and it seems that it would do the job. But is there a quicker solution however?

–

Thinking back, I will just try to affect Object1.AudioListener.volume and Object2.AudioListener.volume from the script which controls when the overall, lets call it master, volume has to change. Probably I shouldn't post before I try some workarounds. But except of that I was looking for a quick, yes/no, answer, this last idea of mine wouldn't be feasible for a big number of objects with audio listeners or if it was not known which instances would have audio listeners, I guess.

–

1 Answer

1

I’m not sure why you have two audio listeners.

Anyway, you could use AudioListener.volume to control the volume of the game (assuming one audio listener is used).

Or (untested), you would get all the audio listeners, loop through them, and modify the AudioListener.volume for each.