- Home /
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?
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 :/
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 :/
Answer by aldonaletto · Aug 26, 2011 at 01:04 AM
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
Answer by Beeblebrox · Jul 22, 2016 at 07:39 PM
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.
Answer by Joa1n · Mar 27, 2020 at 12:11 PM
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.
Answer by Maldonad1o · Oct 10, 2020 at 05:47 AM
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