what is wrong in my code ? Adding instantiated players into list [Problem ] ?

Options
Hello All
Actually , what i want to do simply is to access both players from client and server side
the game depends on instantiating 2 players only
one in Host side
and
one in client side
in the first code
i use list to Add both players into it
then i can access the any element in the list from Host or client Side
unfortunately
it just count = 1
not 2
so what is wrong in my code ?

public static List ThePlayers = new List();
private void Awake()
{
DontDestroyOnLoad(this.gameObject);

}
public override void OnJoinedRoom()
{




GameObject obj = PhotonNetwork.Instantiate(P1.name, source_host.transform.position, Quaternion.identity, 0);
if (PhotonNetwork.isMasterClient)
{
obj.tag = "PMaster";

}
else
{
obj.tag = "PClient";

}
ThePlayers.Add(obj);
}



Comments

  • ???
  • ??????????
  • Hi @MostafaYahia,

    OnJoinedRoom is only called on the local client. If a remote clients joins the room, this callbacks is not called on the local client. So each client will only add his own object to the list.

    To add all player objects to the list, you can make this list globally accessible and use for example the Awake function in a script which is attached to a player object and add this object from there. This way it would be done on all clients. For example:
    public void Awake()
    {
        GlobalList.Add(this.gameObject);
    }
    Please note: setting the Tag of an object is not synchronized automatically, you would have to do this on your own for example by using RPCs.