Disable all sounds in Game except background music

I have sounds attached to various game objects in my game and background music to one game object. I want to disable those sounds(like collision sounds,cry sound,shouting sound) but want to play background music continuous. Anybody knows how to do it?

I tried to deactivate camera listener but it mutes all sounds with music.

Before each of your statements to play sounds put an if statement checking for a global bool (eg public bool playSound;) which you just change based on whether you want the sounds playing.
Don’t put the if statement in front of the background music or if you want to disable that as well at any point then use a different bool variable (eg backgroundMusicPlay)

in javascript,

if you want, one method(maybe not the best) would be to add an if statement in all of the objects you want to mute.

function Update() {
     if(yourMainScriptsName.muteNow)) {
            audio.mute = true;
            audio.mute = false;

but you have to set the boolean “muteNow” in your mainScriptName to static

static var muteNow : boolean = (trueorfalseyourchoice);

minus the ( ) around your choice.

i have similar function

i am able to disable button sound perfectly, while having my bg music playing

however, how do i do the opposite.
have my button sounds play while i disable the bg music

and is there a way to stop an audio file tht is currently playing ( not by reducing the volume of audiolistener, cause i need other sounds like button sounds to keep going)

The way i do it is, i have two floats saved in player prefs. one for music volume and one for sound effects volume.
Whenever i trigger an sfx to play, i first check the volume and then play the clip with that volume.
So i just have to change the float in player prefs to quiet one or the other or both.

I know I’m late, but if someone’s looking for a solution here’s mine: Loop through all AudioSources and disable them if there are different of your background music.

foreach(AudioSource i in GameObject.FindObjectsOfType<AudioSource>()) {
            if(i != music) {
                i.volume = i.volume > 0 ? 0 : 1; // or just i.voume = 0 or something