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:
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;
}
}
0
Best Answer
-
The [RPC] attribute is outdated. PUN now uses [PunRPC].
If your PUN version is still using this, please update.
My guess is that the time is not synced at all but the Master simply knows the time.
Using PhotonNetwork.time, you might get better results for the play time. Set the time when the room was created on the game server as a property of the room. Then everyone can calculate the current time as PhotonNetwork.time - timeFromProperty.
Also see:
https://doc.photonengine.com/en-us/pun/v2/gameplay/rpcsandraiseevent
5
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;
}
}0 -
The [RPC] attribute is outdated. PUN now uses [PunRPC].
If your PUN version is still using this, please update.
My guess is that the time is not synced at all but the Master simply knows the time.
Using PhotonNetwork.time, you might get better results for the play time. Set the time when the room was created on the game server as a property of the room. Then everyone can calculate the current time as PhotonNetwork.time - timeFromProperty.
Also see:
https://doc.photonengine.com/en-us/pun/v2/gameplay/rpcsandraiseevent
5