Only play sounds for certain players, not all

Hey folks.

So I was thinking about adding a feature to my game but I’m sort of scratching my head on how to do it. I want to essentially only play certain sounds in the game for certain players. Meaning that if two players stand in the same spot in the world, perhaps only one of the players can hear the sound, while the other cannot.

I tried putting the sound source in a different layer, which is culled by the camera, but no go. I have little experience messing with the audio listener (which is what I thought might provide me with what I need).

Can anyone maybe point me in the right direction here? Is this even possible? I can’t just turn off the audiolistener for the other player because then they’d be unable to hear any sounds at all. I basically just want to isolate certain sounds only being heard by certain people.

Just an idea, heres what I can think of, why dont you make a manager for the sound that you want to be heard or not. for example if this is a FPS game multiplayer, i would make a condition that check if any player near the object that emmit the sound the audio manager will turn on the sound and if the player is far away turn the sound off…and for each player have their own audio manager…

for example a radio sound…I will make a distance check with my player…if the player is near the volume will be at 100% for the radio…and if the player walk away from the radio the volume will decrese to 0% and maybe after it go down to 0% you can either hide the audio or just let it be…

Without knowing exactly how many players you want to hear a sound, and which players, it’s difficult to give a specific answer. Perhaps you could create a list that is attached to each sound object that keeps track of which players are near the sound source. You can then pick and choose who hears what based on whatever your criteria is (i.e. only the first player to arrive, or the most recent player to get within range, or only up to ‘x’ number of players, etc etc).

I use Physics.Overlapsphere and generic lists to keep track of player proximity to certain objects. My game is turn based, so performance is not so much of an issue, if you do try this then it may be worth creating a few extreme examples to ensure that it will work up to the most computationally taxing situation you will encounter.