- Home /
Instantiate player cards copy online at particular positions
I have given individual cards to players and only they can see their cards. now I want to instantiate their card copies on the network at their particular positions. but in this code I keep receiving this error: ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index this is my script:-
using System.Collections; using System.Collections.Generic; using UnityEngine; using Photon.Pun; using Photon.Realtime; using Photon.Pun.UtilityScripts;
public class PhotonPlayerCardsInstance : MonoBehaviourPunCallbacks { public static PhotonPlayerCardsInstance ppci; public GameObject cardCopyPrefab; private int[] arr=new int[15]; private void Awake() { ppci = this; } private void Start() { PlayerCardInstance(); } private int rdPlayer; public void PlayerCardInstance() { if (photonView.IsMine) { for (int i = 0; i < 3; i++) {
rdPlayer = UnityEngine.Random.Range(0, GameControllerMultiplayer.instance.listCard.Count);
GameControllerMultiplayer.instance.Player[i] = GameControllerMultiplayer.instance.listCard[rdPlayer];
GameControllerMultiplayer.instance.listCard[rdPlayer].transform.SetParent(GameControllerMultiplayer.instance.arr_Tf_Player[i], false);
iTween.MoveTo(GameControllerMultiplayer.instance.listCard[rdPlayer],
iTween.Hash("position", GameControllerMultiplayer.instance.arr_Tf_Player[i], "easeType", "Linear", "loopType", "none", "time", 0.4f));
arr[i] = rdPlayer;
}
photonView.RPC("SplitCards", RpcTarget.All, arr);
}
}
[PunRPC]
public void SplitCards(int[] arr)
{
print("We are in split Cards");
for (int i = 0; i < 3; i++)
{
if (PhotonNetwork.LocalPlayer == DelayStartwithfive.instance.playerList[0])
{
GameControllerMultiplayer.instance.otherPlayerone[i] = GameControllerMultiplayer.instance.listCardCopy[arr[i]];
GameControllerMultiplayer.instance.listCardCopy[arr[i]].transform.SetParent(GameControllerMultiplayer.instance.arr_otherplayerone[i], false);
iTween.MoveTo(GameControllerMultiplayer.instance.listCardCopy[arr[i]],
iTween.Hash("position", GameControllerMultiplayer.instance.arr_otherplayerone[i], "easeType", "Linear", "loopType", "none", "time", 0.4f));
}
if (PhotonNetwork.LocalPlayer == DelayStartwithfive.instance.playerList[1])
{
GameControllerMultiplayer.instance.otherPlayertwo[i] = GameControllerMultiplayer.instance.listCardCopy[arr[i]];
GameControllerMultiplayer.instance.listCardCopy[arr[i]].transform.SetParent(GameControllerMultiplayer.instance.arr_otherplayertwo[i], false);
iTween.MoveTo(GameControllerMultiplayer.instance.listCardCopy[arr[i]],
iTween.Hash("position", GameControllerMultiplayer.instance.arr_otherplayertwo[i], "easeType", "Linear", "loopType", "none", "time", 0.4f));
}
if (PhotonNetwork.LocalPlayer == DelayStartwithfive.instance.playerList[2])
{
GameControllerMultiplayer.instance.otherPlayerthree[i] = GameControllerMultiplayer.instance.listCardCopy[arr[i]];
GameControllerMultiplayer.instance.listCardCopy[arr[i]].transform.SetParent(GameControllerMultiplayer.instance.arr_otherplayerthree[i], false);
iTween.MoveTo(GameControllerMultiplayer.instance.listCardCopy[arr[i]],
iTween.Hash("position", GameControllerMultiplayer.instance.arr_otherplayerthree[i], "easeType", "Linear", "loopType", "none", "time", 0.4f));
}
if (PhotonNetwork.LocalPlayer == DelayStartwithfive.instance.playerList[3])
{
GameControllerMultiplayer.instance.otherPlayerfour[i] = GameControllerMultiplayer.instance.listCardCopy[arr[i]];
GameControllerMultiplayer.instance.listCardCopy[arr[i]].transform.SetParent(GameControllerMultiplayer.instance.arr_otherplayerfour[i], false);
iTween.MoveTo(GameControllerMultiplayer.instance.listCardCopy[arr[i]],
iTween.Hash("position", GameControllerMultiplayer.instance.arr_otherplayerfour[i], "easeType", "Linear", "loopType", "none", "time", 0.4f));
}
if (PhotonNetwork.LocalPlayer == DelayStartwithfive.instance.playerList[4])
{
GameControllerMultiplayer.instance.otherPlayerfive[i] = GameControllerMultiplayer.instance.listCardCopy[arr[i]];
GameControllerMultiplayer.instance.listCardCopy[arr[i]].transform.SetParent(GameControllerMultiplayer.instance.arr_otherplayerfive[i], false);
iTween.MoveTo(GameControllerMultiplayer.instance.listCardCopy[arr[i]],
iTween.Hash("position", GameControllerMultiplayer.instance.arr_otherplayerfive[i], "easeType", "Linear", "loopType", "none", "time", 0.4f));
}
}
}
}
please help me out. thank you