Check Players In Room

Options
Hello everyone!
I'm trying to create a little multiplayer videogame in C# with photon and Unity...
I want that (when player is in a room) there is a text on screen which show the numbers of players in the room. Is it possible?
Thanks, LeoMantooo.

Comments

  • jeanfabre
    Options
    Hi,

    yes, it's perfectly doable.

    There is a property called PhotonNetwork.PlayerList which will tell you the number of players in the current room.

    PhotonNetwork.playerList.Length

    So this is what you need to show in your UI.

    Bye,

    Jean
  • afa
    Options
    jeanfabre wrote: »
    Hi,

    yes, it's perfectly doable.

    There is a property called PhotonNetwork.PlayerList which will tell you the number of players in the current room.

    PhotonNetwork.playerList.Length

    So this is what you need to show in your UI.

    Bye,

    Jean



    how to check if there are 2 player in a room ?

    if(PhotonNetwork.playerList.Length = 2){
    }

    is this correct ?
  • jeanfabre
    Options
    Hi,

    there is a player count property inside the room class, so query PhotonNetwork.CurrentRoom.PlayerCount

    https://doc-api.photonengine.com/en/pun/v1/class_room.html#a9e7c93f447ab113f8b6f8fed1502b997

    Bye,

    Jean