Getting Photon Player Names And Putting It Into Text

Hey guys,

How would I go about receiving other Photon players names using PhotonNetwork. Would it go something like this?

foreach (var player in PhotonNetwork.otherPlayers) {
playersInRoom.text = string.Join("\n", playerNames.ToArray());
}

Is this right?

Also, should I put this in the update function? Or is there a better way to do this?

Thanks! :slight_smile:

If you display a list of players, update it only when players join or leave.
Your code looks like you do the work twice: foreach AND .ToArray().
For simplicity, do the foreach and add each name to the string. If you do this rarely (compared to “each frame”), it’s not a big deal.

1 Like