Problem With PlayerList using new UI Unity 5

Options
Hell everyone well I seem to be having a big problem with making a playerlist for my lobby with the new UI. I was told not to use not to use the photonnetwork.Instantiate and just make an rpc call like this:
void OnJoinedRoom() {
        PreLobby();
        GetComponent<PhotonView>().RPC ("UpdatePlayerList", PhotonTargets.AllBuffered);
    }

    [RPC]
    public void UpdatePlayerList() {
        foreach (PhotonPlayer player in PhotonNetwork.playerList) {
            temp = (GameObject)Instantiate(playerButton);
            temp.transform.SetParent(panel_target_PlayerList);
            temp.GetComponentInChildren<Text>().text = "" + player.name;
        }
    }

Basically as soon as a player joins the lobby it calls updateplayerlist but with this code specifically the foreach statement it causes the the gameobject to be created once for each player in the room any time someone joins. I was told to use something like this:
void OnPhotonPlayerConnected(PhotonPlayer newPlayer) {
		temp = (GameObject)Instantiate(playerButton);
		temp.transform.SetParent(panel_target_PlayerList);
		temp.GetComponentInChildren<Text>().text = "" + newPlayer.name;
	}
but that does not seem to do anything sorry i'm a nobb when it comes to making any type of playerlist. Thanks again for any feedback I get.

I was just Told on the Unity help section to do this:

1. When you join the room, loop through the player list and instantiate the buttons.
2. On player connected, add a button.
3. On player disconnected, remove a button.

I some what understand what he means by this but if anyone could elaborate a bit more I would really appreciate it.

Comments