Best way to sync a list in PUN
Hello!
I'm building a ghost hunting game, and my map has many houses, but each game only one house is haunted. The haunted flag is just a private bool on the house.
I'm struggling to sync which house is haunted between the players. I already tried with room custom properties but didn't work...
Here's my snippet to this... any hint of how to do this?
private void Start() { photonView.RPC(nameof(SetGhostRoomRPC), RpcTarget.AllViaServer); } [PunRPC] private void SetGhostRoomRPC() { int luckyNumber; if (PhotonNetwork.IsMasterClient) { luckyNumber = GenerateLuckyNumber(); var customProperties = new Hashtable {{"GhostRoomIndex", luckyNumber}}; PhotonNetwork.CurrentRoom.SetCustomProperties(customProperties); } else { luckyNumber = (int)PhotonNetwork.CurrentRoom.CustomProperties["GhostRoomIndex"]; } _hauntedRooms[luckyNumber].SetAsGhostRoom(); }
0
Answers
-
so when you set customroomproperties that will then cause a network event, which you have to listen for using OnRoomPropertiesUpdate.
i would suggest not doing it that way. try this:
private void Start() { if (PhotonNetwork.IsMasterClient) { int luckyNumber = GenerateLuckyNumber (); photonView.RPC(nameof(SetGhostRoomRPC), RpcTarget.All, luckyNumber); } } [PunRPC] private void SetGhostRoomRPC(int luckyNumber) { _hauntedRooms[luckyNumber].SetAsGhostRoom(); }
0