I need to stop a sound when I go to the area of another sound

I have a ambient sound environment that occupies the entire map area (sound A).
In a specific sector of that map, I have another sound that is activated when the character enter to the second area (sound B).
Anyone know how to make the sound stop when the sound B is activated?
imagine a rain forest with small houses. SoundA would be that rain. But when the character enters inside a house, rain would not be heard, listening instead for example the chimney fire.
Same backwards, when you go outside, you can hear the rain again.

Someone?

just use AudioSource.Stop

Here’s a link to the documentation
link text

look into using fmod. it lets you create zones to play audio and dynamically mixing it when entering in the house like in your example

I would use bools. For example.

//Assuming you have this audio on separate objects and are probably relying on the awake option ?
public GameObject ObjectWithAudio1;
public GameObject ObjectWithAudio2;
public bool InSide;
public bool OutSide;

if (InSide == true)
{
ObjectWithAudio1.SetActive(enabled);
ObjectWithAudio2.SetActive(false);
}
else if (OutSide == true)
{
ObjectWithAudio1.SetActive(false);
ObjectWithAudio2.SetActive(enabled);
}

You would have to use other things to activate the bools if its 2d I usually Toggle the bools based off of in between values kinda like coordinates or something. 3D though would be easier to use Collision or something. Then call the bools from another script or write the Collision on the same script who cares (That’d be easier) Hopefully this helps in some way. There are plenty of tutorials out there.

I would use bools. For example.

    //With this suggestion it's best that you have audio on separate empty GameObjects and use Awake

    public GameObject ObjectWithAudio1;
    public GameObject ObjectWithAudio2;
    public bool InSide;
    public bool OutSide;
    
    if (InSide == true)
    {
       ObjectWithAudio1.SetActive(enabled);
       ObjectWithAudio2.SetActive(false);
    }
    else if (OutSide == true)
    {
       ObjectWithAudio1.SetActive(false);
       ObjectWithAudio2.SetActive(enabled);
    }

You would have to use other things to activate the bools if its 2d I usually Toggle the bools based off of in between values kinda like coordinates or something. 3D though would be easier to use Collision or something. Then call the bools from another script or write the Collision on the same script who cares (That’d be easier) Hopefully this helps in some way. There are plenty of tutorials out there.

It’s a complicated question because you typically don’t want the sound to stop, rather you want it to fade or apply effects. In the example you’d typically want to change the reverb on the audio and fade it when entering a building from the rain rather than have an instant cut to silence.

This, in general, is what audio reverb zones are for. Unity - Manual: Reverb Zones

The general workflow with ambient audio isn’t that you switch it on and off for the player, it’s that you set its drop-off in it’s AudioSource so it will naturally fade over an appropriate distance.