Quantcast
Channel: Photon Server — Photon Engine
Viewing all articles
Browse latest Browse all 1557

Sync data with new players

$
0
0
Hello, I've recently started using PUN, and I'm having trouble syncing data with players that join the server late.

For example, if player 1 has 10 kills, and a new player joins the server, he will see on the score window that the player 1 only has 0 kills because the variable didn't sync with the new player.

How can I add syncing? I've tryed sending an RPC when a new player joins, to all other players like this:


// sync current players data
GameObject[] gos = GameObject.FindGameObjectsWithTag ("Player");
foreach (GameObject go in gos) {
int kills, deaths;
kills = go.GetComponent ().kills;
deaths = go.GetComponent ().deaths;
go.transform.GetComponent ().RPC ("syncData", PhotonTargets.AllBuffered,kills,deaths);
}


[PunRPC]
void syncData(int _kills,int _deaths){
kills = _kills;
deaths = _deaths;
}

but this instead of syncing all the data, just resets the data back to 0.

How can I get the desired effect?

Thanks for your time

Viewing all articles
Browse latest Browse all 1557

Trending Articles