Retrieving Other Photon Player Names

Hey!

public List<string> playersConnected = new List<string>();

    void OnPhotonPlayerConnected (PhotonPlayer newPlayer) {
        foreach (PhotonPlayer _player in PhotonNetwork.playerList) {
            playersConnected.Add (_player.name);
        }

    }

    void OnPhotonPlayerDisconnected (PhotonPlayer otherPlayer) {
        foreach (PhotonPlayer _player in PhotonNetwork.playerList) {
            playersConnected.Remove (_player.name);
        }
    }

This is what I have, and in a way it works. For every player that joins the game it creates a new slot in the variable ‘playersConnected’

The issue however is in the slots of ‘playersConnected’ none of the player’s names are showing up.

Thanks!

Why are you looping again through all players when the connected player is in parameter?

void OnPhotonPlayerConnected (PhotonPlayer newPlayer)
{
       playersConnected.Add (newPlayer.name); // Add name of new connected player
}

Thanks for your reply, however, I’m still having the same problem.

Look: http://imgur.com/a/FyZju

The player’s name does not show up in the list in the inspector.

Any ideas anyone?

Did you set the name to PhotonNetwork.player.name before the client connects to the room (in lobby or some where else)?

2 Likes

Your right! That worked lol, I forgot to set the name to PhotonNetwork.player.name

Thanks! lol