- Home /
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?
Presumably you're activating the "inside the cabin" sound with a trigger? Why not deactivate the rain sound at the same time? (or maybe just reduce the volume quite a bit ins$$anonymous$$d of cutting it off entirely).
Answer by dorusoftware · Jul 01, 2021 at 11:57 PM
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
Answer by FreshYeet · Jul 02, 2021 at 12:21 AM
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.
Answer by tuinal · Jul 02, 2021 at 02:36 AM
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. https://docs.unity3d.com/Manual/class-AudioReverbZone.html
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.
Your answer
Follow this Question
Related Questions
Sound gets loud in while playing game? 1 Answer
How to activate a sound when a player walks through a collider 1 Answer
3d Sound not working? 0 Answers
how to add a sound when collecting coins? 0 Answers
Can i change tha audio driver? 0 Answers