AudioListener.volume doesn't change the volume

Hi everyone !
I’ve made a custom 3D Slider with a box you can slide here is a part of the code

function FixedUpdate () {

VolumeSonore = ((gameObject.transform.position.x - 266.57) * 15.953)/100 ;

AudioListener.volume = VolumeSonore  ;

print(VolumeSonore);

}

so when the box in on the left side of the slider , it prints 0 and when it’s on the other side it prints 1 , but the sound doesn’t change (there is just a music attached to the main camera).

Actually , when it’s on the left side , the music sounds more laggy , but actually as loud as on the right side .

Thanks for reading

Could your audio source be using [ignoreListenerVolume][1]? [1]: http://unity3d.com/support/documentation/ScriptReference/AudioSource-ignoreListenerVolume.html

No it's not using ignoreListenerVolume , i've tried adding a script to the camera which makes the ignoreListenerVolume false and true , but both doesn't make it work :/

Is your sound 2d or 3d in the import settings?

my sound was 3D in the import settings , but I changed it to 2D and the volume is still the same when I move the slider :/

4 Answers

4

I’ve tested this script and it worked fine. My scene is different, so I had to adapt the numbers - in consequence, the volumeSonore value ranged from -0.5 to +7, but this value is internally clamped to 0…1, so it worked as expected.

I suspect there’s something else altering the volume. Could you have some other lost script changing the volume elsewhere? Try to create a new scene and place only the essential objects to see if it works.

I feel so dumb , the script was applied at another object I forgot about , I thought the only fact that it was printing the good value would be enough . Thank you so much !

This happens very often: scripts forgotten or attached to wrong objects by mistake are hard to find, and may bother us to death

Another possibility: you have more than one AudioListener in the scene.

In that case Unity would spam warnings in the console. You can't miss that.

Your code is updating a saved value in PlayerPrefs called VolumeLevel, but it doesn’t actually tell Unity to change the volume at any point.

Your code is refreshing a spared an incentive in player preferences called volume level, yet it doesn’t really advise Unity to change the volume anytime mycfavisit