So im trying to use RPC and send a list of int and an int as parameters, however, while the function sends the int list correctly, the int value it sends is wrong and different for each client even though I'm send the same value to all of them.
This is the RPC method;
[PunRPC]
void GetPlayerCards(int[] _cardListInt, int _gCard)
{
if(intPlayerCardlist.Count == 0)
{
intPlayerCardlist.AddRange(_cardListInt);
}
foreach (int cardInt in intPlayerCardlist)
{
if(MyCardlist.Contains(gameFullCardlist.cardList[cardInt])) continue;
else MyCardlist.Add(gameFullCardlist.cardList[cardInt]);
}
groundCard = gameFullCardlist.cardList[_gCard];
Debug.Log("value: " + _gCard + " card name: " + groundCard);
}
This is the call method which is being called from a room instantiated object that belongs to the master client:
int[] List1 = cardList1.ToArray();
int[] List2 = cardList2.ToArray();
int[] List3 = cardList3.ToArray();
int[] List4 = cardList4.ToArray();
int[] List5 = cardList5.ToArray();
int gCard = cardList5[0];
PhotonView PV_P1 = gamePlayersList[0].GetComponent<PhotonView>();
PhotonView PV_P2 = gamePlayersList[1].GetComponent<PhotonView>();
PhotonView PV_P3 = gamePlayersList[2].GetComponent<PhotonView>();
PhotonView PV_P4 = gamePlayersList[3].GetComponent<PhotonView>();
PV_P1.RPC("GetPlayerCards", PV_P1.Owner, List1, gCard);
PV_P2.RPC("GetPlayerCards", PV_P2.Owner, List2, gCard);
PV_P3.RPC("GetPlayerCards", PV_P3.Owner, List3, gCard);
PV_P4.RPC("GetPlayerCards", PV_P4.Owner, List4, gCard);
if you notice im send the same value for all clients but im getting different results, see the log below:
The game Manager and players are being instantiated from an empty game object in each client scene that uses the following script;
private void Awake()
{
//Order of Instantiation is important
PhotonNetwork.InstantiateRoomObject(InstantiatedPlayersListGameobject.name, Vector3.zero, Quaternion.identity);
PhotonNetwork.InstantiateRoomObject(cardsDeck.name, Vector3.zero, Quaternion.identity);
PhotonNetwork.InstantiateRoomObject(GameplayManager.name, Vector3.zero, Quaternion.identity);
}
void Start()
{
if(PhotonNetwork.IsConnectedAndReady)
{
if (playerPrefab != null)
{
GameObject playerInstantiation = PhotonNetwork.Instantiate(playerPrefab.name, Vector3.zero, Quaternion.identity);
playerInstantiation.transform.SetParent(InstanceParent.transform, false);
playerInstantiation.transform.localScale = Vector3.one;
playerInstantiation.transform.localPosition = Vector3.zero;
// playerInstantiation.name = (playerInstantiation.GetComponent<PhotonView>().Owner.NickName + " - AN: " +
// playerInstantiation.GetComponent<PhotonView>().Owner.ActorNumber);
Debug.Log("player instantiated");
}
else
{
Debug.Log("Place player Prefab");
}
}
}