h heath h heath - 1 month ago 4
C# Question

How to turn off all the sounds in unity on click of button

public void Click(){
private void changeState(){
isClicked = !isClicked;
if(isClicked) myBtn.image.sprite = Play;
else myBtn.image.sprite = Pause;

I have attached the above code to change the button image.
and now how can I turn off all the sounds.
Any help would be great.Thank you.


In addition to the suggestion in first answer, you can also disable the audio-listener in your scene. Or, if you can access all the audio-sources you can stop each one of them.

public AudioListener audioListener;
public List<AudioSource> audioSources;

void OnMouseDown() {
    foreach(AudioSource audioSorce in audioSources) {
    if(audioListener != null) {
        audioListener.enabled = false;