- Home /
Audio listeners in multiplayer game
I'm working on adding audio to my multiplayer game. There is an Audio Listener attached to the player prefab I instantiate for each new player. It works with only one player connected, but with more than one player connected Unity says there are too many audio listeners in the scene. I tried addingif(!networkView.isMine){ enabled = false; }
to the script, but that didn't work.
Answer by cmpgk1024 · Aug 08, 2013 at 07:32 PM
I got it working by modifying my script that I used to disable the camera and disabling the audio listener in it. Here's the code: #pragma strict public var cam:Camera; public var ears:GameObject; function Start () { if(networkView.isMine){ cam.active = true; ears.GetComponent(AudioListener).enabled = true; } else{ cam.active = false; ears.GetComponent(AudioListener).enabled = false; GetComponent(MouseLook).enabled = false; } }
Answer by Seizure · Aug 08, 2013 at 05:31 PM
Did you add the script and attach to the camera or is it on another player. Also try
if(!camera.networkView.isMine){ Camera.main.camera.enabled = false; }
Answer by VolureDarkAngel · Aug 08, 2013 at 05:31 PM
the audio listener is where the current player hears things (their ears), each player would have their own audio listener, however hearing audio from another persons ears does not make sense.
Therefore only the active player should have an audio listener, and the other players should have their own ears.
Mixing the audio for split screen is beyond my expertise, so you would have to research that.
here is a link to a unity answer dealing with Split screen and Multiple audio listeners, in case this is your scenario.
http://answers.unity3d.com/questions/289325/how-to-have-two-audio-listenerssplitscreen.html
This isn't split screen - it's played on two different computers so mixing won't be an issue. I just have to disable any ears that are not the local player's.
Your answer
![](https://koobas.hobune.stream/wayback/20220613111802im_/https://answers.unity.com/themes/thub/images/avi.jpg)