Second Player Name not exist when Function OnPlayerEnteredRoom

Options
Hello all!

im having a problem with the name of the second player in my lobby which is always empty.

First of all at the start of the game the user logs in -> the login system is build with playfab but everything i do is API call and create a new playerobject with the result.name.

When 1 player is creating the room via button i want him and his informations gettings set to the left side of the room this works fine!

when the second player logs in and tries to find a room via button je joins the room and the info is also setup on the right side of them room.

SO the one who joins the room gets the playername of boths players.

But the one who created the room just sees his own name because the given parameter newPlayer.Nickname is empty and i don't get why.
public override void OnPlayerEnteredRoom(Player newPlayer)
    {
        playerText[1].text = "";
        base.OnPlayerEnteredRoom(newPlayer);
        
        for (int i = 0; i < PhotonNetwork.PlayerList.Length; i++)
        {
            [b]playerText[1].text += newPlayer.NickName;[/b]
        }
    }

____________________________________________________________________________________

This is my code when a player joins the room - the one who creats it gets
lobbyCreated == true

the one who joins
lobbyCreated == false

so i know who gets which place
public override void OnJoinedRoom()
    {
        Player[] photonPlayer = PhotonNetwork.PlayerList;

        if (PhotonNetwork.PlayerList.Length != 0 && lobbyCreated == true)
        {
            //PhotonNetwork.NickName = players[0]._DisplayName + "Created";
            //Debug.Log(players[0]._DisplayName + " or " + PhotonNetwork.NickName + " created romm");

            //PhotonNetwork.NickName = players[0]._DisplayName;

            PhotonNetwork.NickName = "Player" + Random.Range(1, 9999);
            Debug.Log("Create Playername: " + PhotonNetwork.NickName);

            playerText[0].text = photonPlayer[0].NickName;

            /*
            for (int i = 0; i < photonPlayer.Length; i++)
            {
                //photonPlayer[i].NickName = players[i]._DisplayName;
                
            }
            */
            foreach (var Enableobj in EnableObjectsOnConnect)
            {
                Enableobj.SetActive(true);
            }
            foreach (var DisableObj in DisableObjectsOnConnect)
            {
                DisableObj.SetActive(false);
            }
        }
        else if (PhotonNetwork.PlayerList.Length != 0 && lobbyCreated == false)
        {
            //PhotonNetwork.NickName = players[0]._DisplayName + "Joined";
            //Debug.Log(players[0]._DisplayName + " or " + PhotonNetwork.NickName + " joined room");

            //PhotonNetwork.NickName = players[0]._DisplayName;

            PhotonNetwork.NickName = "EnemyPlayer" + Random.Range(1,9999);
            Debug.Log("Join Playername: " + PhotonNetwork.NickName);

            playerText[1].text = photonPlayer[0].NickName;

            for (int i = 0; i < photonPlayer.Length; i++)
            {
                playerText[i].text = photonPlayer[i].NickName;
            }

            foreach (var Enableobj in EnableObjectsOnConnect)
            {
                Enableobj.SetActive(true);
            }
            foreach (var DisableObj in DisableObjectsOnConnect)
            {
                DisableObj.SetActive(false);
            }
        }
        else
        {
            Debug.Log("Fail");
            userExist = false;
            lobbyCreated = false;
            foreach (var Enableobj in EnableObjectsOnConnect)
            {
                Enableobj.SetActive(false);
            }
            foreach (var DisableObj in DisableObjectsOnConnect)
            {
                DisableObj.SetActive(true);
            }
            StartCoroutine(alert.CreateNewAlert("Couldn't join. Please create a room!"));
        }
    }

Maybe im just doing a big failure here :/
Thanks in advance this is legit frustrating.

Comments

  • Unravel
    Options
    I already fixed this problem on my own, took me some time but i finaly did it. I can't even say if it's the best version of code but it works!

    Thanks all who tried understanding this.