PUN RPC not working

I'm try to use RPC to broadcast play time,
but only masterClient is working, looks like other clients didnt get data.

code:
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class Photon_RPC : Photon.MonoBehaviour { public int PLAY_TIME = 0; public Text text_time; // Use this for initialization void Start () { } // Update is called once per frame void Update () { if (PhotonNetwork.isMasterClient) { if (PLAY_TIME <= 100000000) { if (Time.deltaTime >= 1f) { PLAY_TIME += (int)Time.deltaTime; } else { PLAY_TIME += 1; } } if (PhotonTargets.Others != null) { photonView.RPC ("SetStatus", PhotonTargets.Others, PLAY_TIME); } } text_time.text = "Time: " + PLAY_TIME.ToString (); } [RPC] void SetStatus(int p_time){ PLAY_TIME = p_time; } }

Best Answer

Answers

  • Repost the code:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;

    public class Photon_RPC : Photon.MonoBehaviour {

    public int PLAY_TIME = 0;
    public Text text_time;

    // Use this for initialization
    void Start () {

    }

    // Update is called once per frame
    void Update () {
    if (PhotonNetwork.isMasterClient) {
    if (PLAY_TIME <= 100000000) {
    if (Time.deltaTime >= 1f) {
    PLAY_TIME += (int)Time.deltaTime;
    } else {
    PLAY_TIME += 1;
    }
    }
    if (PhotonTargets.Others != null) {
    photonView.RPC ("SetStatus", PhotonTargets.Others, PLAY_TIME);
    }
    }
    text_time.text = "Time: " + PLAY_TIME.ToString ();
    }

    [RPC]
    void SetStatus(int p_time){
    PLAY_TIME = p_time;
    }
    }
  • Tobias said:

    The [RPC] attribute is outdated. PUN now uses [PunRPC].
    If your PUN version is still using this, please update.

    Replace [RPC] with [PunRPC] is helpful, thx.