- Home /
Playing Audio Over Network
My class is making a network game for our final project and i can't seem to get the audio to work properly. I tried rpc calling it and passing it a location but it seems to get the location of each player that calls it. the code i used is here
networkView.RPC("shotFired", RPCMode.All, transform.position);
[RPC]
void shotFired(Vector3 pos)
{
AudioSource.PlayClipAtPoint(audioClips[0], pos);
}
what do you mean gets the location of each player that calls it?
When the rpc calls there is a sound on each player and not just the player that called it
not sure but could it be because the audio source on each player does not have the right falloff and so it does not get lower with distance?
I tried setting that down to 10 but i was looking in the scene view while running off the host. And the host and the other player were both playing the sound
not sure what the problem is but maybe this is a way to cheat it. create an empty game object, name it firesound, attach a audiosource to it and turn on play on awake. make sure your sound is set to 3d sound in the import settings and attach your sound to the object. Then in the rpc function instantiate the fire sound gameobject at the inco$$anonymous$$g vector3. something like.
var FireSound : GameObject
@RPC function shotFired(pos : Vector3){ var FireSoundClone : GameObject.Instantiate(FireSound,pos,transform.rotation); Destroy(FireSoundClone,1); }
Your answer
Follow this Question
Related Questions
client to client ping - NAT punchthrough 1 Answer
RPC Call doesnt get called 2 Answers
Multiplayer Moving Bullet 1 Answer
Problem with identifying players in network 1 Answer
Networking RPC sends to wrong target 0 Answers