This works for audio being passed directly to the output but if you want the sounds to have an affect in the 3D space you will still need to control the volume of each audio source.
For controlling the snapshots you could do something like this:
Code:
public class FootStepState : StateBehavior
{
public AudioMixerSnapshot standing;
public AudioMixerSnapshot crouching;
[SerializeField] protected bool isCrouching = false;
public bool crouchVolume { get { return isCrouching; } set { isCrouching = value; } }
public override void StateChange()
{
base.StateChange();
if (isCrouching) crouching.TransitionTo(0f);
else standing.TransitionTo(0f);
}
}
Then make a preset that listens for the crouching state
If you want to have your changing sound affect the reactions of AI you could do something like this (add it to the player's pelvis), though it's probably not the neatest way to do it.
maybe someone with more programming skills could suggest a better way.
Code:
public class DynamicFootStepState : StateBehavior
{
public AudioSource[] foot;
public float standingVolume = 0.4f;
public float croucthingVolume = 0.05f;
[SerializeField] protected bool isCrouching = false;
public bool crouchVolume { get { return isCrouching; } set { isCrouching = value; } }
public override void StateChange()
{
base.StateChange();
if (isCrouching)
{
foot = gameObject.GetComponentsInChildren<AudioSource>();
foreach (var item in foot)
{
item.volume = croucthingVolume;
}
}
else
{
foot = gameObject.GetComponentsInChildren<AudioSource>();
foreach (var item in foot)
{
item.volume = standingVolume;
}
}
}
}