Multiplayer audio.

hello guys. How can i make script to play audio on all players on multiplayer server. The audio have to be played when i will shoot.

I apologize for mistakes.

You would have a script that handles audio and send an RPC to all clients to tell it to play the sound. Photon for example has RPC’s.

We’re currently working on adding Photon support to our audio plugin Master Audio to make this “code-free” for most cases.

Hi. I have this error:
NullReferenceException
UnityEngine.NetworkView.RPC (System.String name, RPCMode mode, System.Object[ ] args) (at C:/buildslave/unity/build/artifacts/generated/common/runtime/NetworkingBindings.gen.cs:401)
RPCs.SendReloadRPC (Vector3 position) (at Assets/_Scripts/RPCs.cs:13)
Weapon_rifle_test.Update () (at Assets/_Scripts/Weapon_rifle_test.cs:132)

This is code:
RPCs.cs

using UnityEngine;
using System.Collections;

public class RPCs : MonoBehaviour {

    //Variables
    public AudioClip reload;

    public void SendReloadRPC(Vector3 position)
    {
        NetworkView nView = new NetworkView();
        nView.RPC ("SendToServerPlayerWhoReloadTransform",RPCMode.All , position);
    }

    [RPC]
    void SendToServerPlayerWhoReloadTransform (Vector3 pos)
    {
        Debug.Log ("Przesłano do rpc");
        AudioSource.PlayClipAtPoint (reload, pos);
    }
}

Weapon_rifle_test:

using UnityEngine;
using System.Collections;
using UnityEngine.Networking;

[RequireComponent(typeof(AudioSource))]
public class Weapon_rifle_test : NetworkBehaviour {
   
    private float timer = 0;
    private string currentState;
    private Animator animator;
    private float range = 20.0f;
    private GameObject pistolSparks;
    private  Vector3 PlayerWhoShotPosition;
    [SerializeField] private  Vector3 MyPosition;
    private Vector3 fwd;
    private RaycastHit hit;
    public ParticleEmitter emitter;
    public AudioClip shoot;
    public AudioClip reload;
    private static Transform trans;
    public string informacjacorobi;
    private float zoomFieldOfView = 40.0f;
    private float defaultFieldOfView = 60.0f;
    private static int animacjatest = 0;
    public string scopeInAnim;
    public string scopeOutAnim;
    public NetworkView networkViewComponent;
    public Player_shoot playershootscript;

    //Ammo
    private static float FireRate = 0.085f;
    private static float nextShot = 0.0f;
    private static float reloadingTime = 3.0f;
    private static int currentAmmo = 0;
    private static int maxAmmo = 30;
    private static int allAmmo = 0;
    private static int shootedammo = 0;
    private static int minAmmo = 0;
    private static int magazines = 3;
    //End ammo

    private static Rect positionOfAmmoInfo = new Rect(1140,750,300,100);
   
    private static bool canfire = true;
    public bool czyreloading;
    // Use this for initialization
    void Start () {
            Cursor.visible = false;
            if(isLocalPlayer)
        emitter = GameObject.Find ("Sparks").GetComponent<ParticleEmitter> ();
        MyPosition = transform.position;
        networkViewComponent = new NetworkView();
        emitter.emit = false;
            trans = transform;
            currentAmmo = maxAmmo;
            animator = GetComponent<Animator> ();
            currentState = "";
            informacjacorobi = "";
            czyreloading = false;
            allAmmo = maxAmmo * magazines;
        playershootscript = GetComponentInParent<Player_shoot> ();

    }
   
    void Update () {
            fwd = transform.TransformDirection (Vector3.forward);

       

            if (Input.GetButton ("Fire1")) {
           
                if (canfire) {
                    StartCoroutine ("fire");
                }
            }
            if (gameObject.GetComponentInParent<Camera> () is Camera) {
                Camera cam = gameObject.GetComponentInParent<Camera> ();
                if (Input.GetButtonDown ("Fire2")) {
                    animator.SetBool ("ScopeIn", true);
                    animator.SetBool ("ScopeOut", false);
                    for (int x = 0; x < 20; x++) {
                        cam.fieldOfView--;
                    }

                }
                if (Input.GetButtonUp ("Fire2")) {
                    if (cam.fieldOfView < defaultFieldOfView) {
                        animator.SetBool ("ScopeIn", false);
                        animator.SetBool ("ScopeOut", true);
                        for (int x = 0; x < 20; x++) {
                            cam.fieldOfView++;
                        }


                   
                    }
                }
            }

            if (currentAmmo == 0) {
                canfire = false;
                emitter.emit = false;
                StopCoroutine ("fire");
                if (Input.GetButtonUp ("Fire1") && !czyreloading) {
                    StartCoroutine ("reloading");
                    GetComponentInParent<RPCs> ().SendReloadRPC (transform.position);
                }
            }
       
            if (shootedammo == allAmmo) {
                canfire = false;
                emitter.emit = false;
                StopCoroutine ("fire");
                StopCoroutine ("reloading");
            informacjacorobi = "Out of ammo!";
            }
       
            if (Input.GetButtonUp ("Fire1")) {
                emitter.emit = false;
                playershootscript.PositionYfromCrosshair = 0;

            }
            if (Input.GetButtonDown ("Reload")) {
                if (currentAmmo != maxAmmo && !czyreloading) {
                    StartCoroutine ("reloading");
                    GetComponentInParent<RPCs> ().SendReloadRPC (transform.position);
                }
           
        }
    }




    public IEnumerator reloading()
    {

        informacjacorobi = "Reloading! Can't change weapon!";
        canfire = false;
        czyreloading = true;
        AudioSource.PlayClipAtPoint (reload, trans.position);
        Vector3 PlayerWhoReloadPosition = transform.position;
        yield return new WaitForSeconds (reloadingTime);
        currentAmmo = maxAmmo;
        informacjacorobi = "";
        czyreloading = false;
        canfire = true;
    }

}

This isn’t all of code because it will be deleted in future. Can you help mi?

Following up to what I said earlier, we did release Master Audio Multiplayer in the Asset Store. 93 RPCs at a reasonable price and it’s dead simple to use (normally will not need to write any code). Link in my signature.

Does anyone got an answer on that? No Advertising, an answer!