OnPlayerNumberingChanged() is executed twice

Options
Hello,

I'm new to Photon and try to build my own Lobby based on the Lobby Tutorial on the website. That works quite good, but I have one problem I can't solve myself.

I looked into the Asteroids Demo code, so I registered my own method to the OnPlayerNumberingChanged() event. When I create a new room, this method is executed twice, maybe someone can help?
public class Lobby : MonoBehaviourPunCallbacks
{
    public override void OnEnable()
    {
        base.OnEnable();
        PlayerNumbering.OnPlayerNumberingChanged += OnPlayerNumberingChanged;
    }

    public override void OnDisable()
    {
        base.OnDisable();
        PlayerNumbering.OnPlayerNumberingChanged -= OnPlayerNumberingChanged;
    }

    void OnPlayerNumberingChanged()
    {
        Debug.Log("OnPlayerNumberingChanged() CALLED! Players="+ PhotonNetwork.PlayerList.Length);
        GameObject playerContainer = roomLobby.transform.Find("Player Container").gameObject;

        foreach (Photon.Realtime.Player p in PhotonNetwork.PlayerList) {
            GameObject roomLobbyPlayer = Instantiate(roomLobbyPlayerPrefab);
            roomLobbyPlayer.transform.Find("Player Slot Text").GetComponent<TextMeshProUGUI>().text = p.ActorNumber + ")";
            roomLobbyPlayer.transform.Find("Player Name Text").GetComponent<TextMeshProUGUI>().text = p.NickName;
            roomLobbyPlayer.transform.SetParent(playerContainer.transform, false);
        }
    }
}

Comments

  • Vencarii
    Options
    Uhm sorry for messing the code up, I used the Code tag on the format button. :/