Search Unity

Count players in lobby

Discussion in 'Multiplayer' started by christianlebedev1, Dec 27, 2021.

  1. christianlebedev1

    christianlebedev1

    Joined:
    Dec 5, 2020
    Posts:
    14
    Hello, how can I make a player count in a lobby, for example 1/2?
    I can not understand
    Code (CSharp):
    1. public override void OnRoomListUpdate(List<RoomInfo> roomList)
    2.     {
    3.         foreach(Transform trans in roomListContent)
    4.         {
    5.             Destroy(trans.gameObject);
    6.         }
    7.         for (int i = 0; i < roomList.Count; i++)
    8.         {
    9.             if (roomList[i].RemovedFromList)
    10.                 continue;
    11.             Instantiate(roomListItemPrefab, roomListContent).GetComponent<RoomListItem>().SetUp(roomList[i]);
    12.         }
    13.     }
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,072
    The OnRoomListUpdate provides an update to any list you already keep. Don't destroy the complete content when just receiving updates...

    Yes, you could count all players in the room list (using RoomInfo).
    Alternatively, there are "Lobby Stats" provided in intervals.