Problem with add Component via RunRPC
Options
Hey i'm working with photon for the first time so please be patient with me.
My goal is to give two Players a component.
My Problem is that sometimes no one gets the script and sometimes only one player gets the script.
I do this through a gameobject in the scene.
_____________________________________________________________
if (PhotonNetwork.IsMasterClient)
{
List<Player> Players = new List<Player>();
for (int i = 0; i < PhotonNetwork.PlayerList.Length; i++)
{
Players.Add(PhotonNetwork.PlayerList);
}
string p1;
string p2;
do
{
int randomPlayer1 = Random.Range(0, Players.Count);
p1 = PhotonNetwork.PlayerList[randomPlayer1].NickName;
int randomPlayer2 = Random.Range(0, Players.Count);
p2 = PhotonNetwork.PlayerList[randomPlayer2].NickName;
} while (p1 == p2);
Debug.Log(p1 + " " + p2);
photonView.RPC("ChoosePlayer", RpcTarget.AllBufferedViaServer, p1, p2);
}
[PunRPC]
public void ChoosePlayer(string p1, string p2, PhotonMessageInfo info)
{
Debug.Log(p1 + " " + p2);
GameObject.Find(p2).AddComponent<Player>();
GameObject.Find(p1).AddComponent<Player>();
}
_____________________________________________________________
It would be very nice if someone could help me
thanks
My goal is to give two Players a component.
My Problem is that sometimes no one gets the script and sometimes only one player gets the script.
I do this through a gameobject in the scene.
_____________________________________________________________
if (PhotonNetwork.IsMasterClient)
{
List<Player> Players = new List<Player>();
for (int i = 0; i < PhotonNetwork.PlayerList.Length; i++)
{
Players.Add(PhotonNetwork.PlayerList);
}
string p1;
string p2;
do
{
int randomPlayer1 = Random.Range(0, Players.Count);
p1 = PhotonNetwork.PlayerList[randomPlayer1].NickName;
int randomPlayer2 = Random.Range(0, Players.Count);
p2 = PhotonNetwork.PlayerList[randomPlayer2].NickName;
} while (p1 == p2);
Debug.Log(p1 + " " + p2);
photonView.RPC("ChoosePlayer", RpcTarget.AllBufferedViaServer, p1, p2);
}
[PunRPC]
public void ChoosePlayer(string p1, string p2, PhotonMessageInfo info)
{
Debug.Log(p1 + " " + p2);
GameObject.Find(p2).AddComponent<Player>();
GameObject.Find(p1).AddComponent<Player>();
}
_____________________________________________________________
It would be very nice if someone could help me
thanks
0