- Home /
Question by
Dark_Templar · May 11, 2014 at 08:49 AM ·
networkingphotonrpc
Synchronize array with simultaneous access via Photon Network RPC
Hi!
I have list with several items
var list = new List<int>();
list.Add(1);
list.Add(2);
list.Add(3);
list.Add(4);
Each player can take item from it, this done locally, not via rpc. When player take item, rpc sended to other players to remove item from list.
RemoveItemFromList(itemId);
_photonView.RPC("RemoveItem", PhotonTargets.Others, item.Id);
[RPC]
private void RemoveItem(int itemId)
{
RemoveItemFromList(itemId);
}
private void RemoveItemFromList(int itemId)
{
var item = list.First(x=>x == itemId);
list.Remove(item);
}
It's working normal, but when several players get items simultaneously i have an error. Because two players can hit the same item. How can i sync them? I am using Photon Cloud.
Comment
Best Answer
Answer by Dark_Templar · May 13, 2014 at 11:21 AM
Solve my problem. First i check list on master client, and then send changes to all other players.