I’m working on something like a soccer game. I have a prefab of a single player. When the match starts I create many instances of that prefab. One of them is placed under human control, and the others under AI control. To emphasise; my human player is the same prefab as my NPCs.
The player prefab has a number of AudioSources, which are routed to various AudioMixerGroups, all of which are within a single AudioMixer that is used for player sounds. That “player sounds” AudioMixer eventually feeds into my master mixer.
I’d like to give extra emphasis to the individual player instance that is under human control. Or to put it another way, I’d like to surpress sounds from non-human controlled player instances. I’d rather not adjust the volume parameter of each AudioSource under AI players, because I already have other code that updates those volumes from other gameplay parameters, and I’d like that code to continue to deal with values from 0 to 1. I don’t think I can make use of distance-based rolloff values, since my camera is roughly equidistant from all player instances.
I’d prefer to do it using AudioMixerGroups, since they’re new and shiny. Ideally I’d like to achieve the same effect as if I could duplicate the entire “player sounds” mixer for each and every player, setting them to a snapshot for “human” or “ai”. Failing that, to duplicate it for just the human player, and have all AI players use the original.
My first attempt was that I could create a clone of the “player sounds” AudioMixer at runtime using an Instantiate call, passing in the original mixer. The call appears to work in the MonoDevelop debugger (I get a new AudioMixer instance), but Unity’s Audio Mixer window does not show the new instance. Also, if I try to apply snapshots on the newly-created duplicate, they get applied on the original instead (or possibly “as well”).
Is this approach worth persevering with? How do other people achieve the same thing?