- Home /
Dull all sounds except one
Hi! I'm looking for a way to decrease volume of all sounds except one in my scene by proximity to an object, while increasing the volume of the exception sound. I tried using the microphone settings, but then I can't hear the sound I'm looking to make louder. Any ideas how this could be achieved? Thanks!
Answer by Woj_Gabel_FertileSky · Aug 22, 2012 at 01:02 PM
Hi. First find all your sound objects and add them to an array for reference.
quick search: http://answers.unity3d.com/questions/304182/controlling-all-sounds-from-their-volume-point.html
var sounds : AudioSource[] = FindObjectsOfType(AudioSource) as AudioSource[];
Then find distance from said object to other(I don't know to what, your question was not clear). http://docs.unity3d.com/Documentation/ScriptReference/Vector3.Distance.html
Then, in loop adjust volume of other sounds in the array. Increase volume of chosen sound by lerp distance. Oh, and figure out how to distinguish chosen sound from the others :)
Thats perfect, thanks! Looks like the poster below has even gone and written the code!
Answer by Arshia001 · Aug 22, 2012 at 01:05 PM
foreach (AudioSource s in (AudioSource[])findSceneObjectsOfType(typeof(AudioSource)))
if (!ReferenceEquals(s, theOneYouDontWantToDull))
s.volume = 0.1f; //or whatever you want to set it to
"the poster below" was kinda in a hurry, so I didn't have time to really explain, but it seems that will be no longer needed :D
Your answer
![](https://koobas.hobune.stream/wayback/20220613080020im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Mute volume / sound problem 1 Answer
Far- heard sound using Detonator 2 Answers
Every sound is too quiet 0 Answers
Change sound dependent on slider? 1 Answer
Sound volume issue 1 Answer