Search code examples
unity-game-enginephoton

Adding names for players Unity and Photon


I'm using unity with photon and I'm having a problem making different names for every player that joins the room. What I want to make is when a player joins the lobby i want him to take a name like

NewPlayer.gameobject.name = "Player " + the number of players that were in when he joined

. If you want any more information please reply to this post and ill inform you with your question. Thanks I want the first player that joined the room his name to be "Player 1" the second "Player 2" and so on. I'm using photon.


Solution

  • You can use PhotonNetwork.NickName which is synchronized across all clients in the room. Than using PhotonView components attached to your players you use get the Nickname as:

    var photonView = GetComponent<PhotonView>();
    photonView.Owner.NickName;
    

    Or based on your input you can use:

    Player.ActorNumber
    

    which is the id of the player in current room.