I'd set the ambient sounds to a different audiolayer in the builtin mixer, and set the volume based on the context from there.
Maybe control it by triggerboxes, one for inside the house, and one outside the door.
Have the trigger inside the house send info to lower the ambient sounds as soon as its triggered, and same for the one outside the house.
I would probably use 'On Trigger Enter' in the 'Trigger Event' action.
The fading could be as easy as using 'Float Interpolate', or 'Float Add' and 'Float subtract' with a clamp.
If you have trouble with fading in between with 'Float Interpolate', then you need to add some logic that dictates if the value hasn't fully faded to another value, then fade from current to whatever it needs to fade to.
Bear with me here.
Say it takes two seconds to fade from 1 to 0, and in the span of one second the script needs to fade back to 1 again.
It's currently at 0.5, but if the previous logic was to only have it fade from 1 to 0, and from 0 to 1, the volume might suddenly jump from its current value of 0.5 to 0 in order to fade back to 1 again.
You'd need to store the value in a 'current' variable and set it to a 'previous' variable once the trigger is hit.
- In one state, the variable 'currentValue' is 1, and is fading towards 0, stored as 'previousValue'
- Trigger is hit
- 'previousValue' is at 0.5
- Before a 'Fade to 1' state, have another state that sets the value of 'currentValue' to whatever 'previousValue' was before the trigger
- In the next state, the variable 'currentValue' is at 0.5 and is fading towards 1
However, using 'Float Interpolate' fades based on time, so going from 0.5 to 1 in two seconds will increment slower than 0 to 1.
Use 'Float Add' and 'Float Subtract' for uniformly incrementing values, and with a clamp.
Then its as simple as:
- In one state, 'currentValue' is being subtracted from
- Trigger is hit
- 'currentValue' is at 0.5
- In the next state, 'currentValue' is being added to
No need to store the value in a different variable, just add and subtract, with a clamp of course.