- Home /
how can mute all sounds in the Scene?
It's my code to play a sound and it works fine.
public AudioSource sound1;
public AudioSource sound2;
public AudioSource sound3;
public AudioSource sound4;
public void Sound1(){
sound1.Play ();
}
public void Sound2(){
sound2.Play ();
}
public void Sound3(){
sound3.Play ();
}
public void Sound4(){
sound4.Play ();
}
they work fine how could I mute them when I click on a button? I mean I can use sound.volume = 0; ,but I have to use it for all of them ? any idea?
Hi, What you could do is have your audio source on it's own game-object and create an instance of it every time you want to play the sound. So, when an audio event happens a method is called in some sort of audio controller script that instantiates the audio source game-object. You will need to work out how you want to handle the instances (pooling, caching, etc.,). To keep things simple the audiosource game-object could just expire (be deactivated) with a co-routine once the sound has finished playing. Hope that makes sense. Best of luck!
Hi dear,I just made this code public AudioSource buttonClick; public AudioSource buttonClick1; public AudioSource buttonClick2; public AudioSource buttonClick3;
public void ButtonClick(){ buttonClick.Play (); }
public void ButtonClick1(){ buttonClick1.Play (); } public void ButtonClick2(){ buttonClick2.Play (); } public void ButtonClick3(){ buttonClick3.Play (); }
Is it Ok to do something like this?
Answer by J_LTD · Aug 18, 2017 at 01:58 PM
You could just disable the audio listener via the script
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Flip over an object (smooth transition) 3 Answers