Search Unity

Third Party Displaying people in current room (PUN 2)

Discussion in 'Multiplayer' started by Johan_Liebert123, May 7, 2021.

  1. Johan_Liebert123

    Johan_Liebert123

    Joined:
    Apr 15, 2021
    Posts:
    474
    Hello all, I've just started working on a multiplayer game using Photon. Whats happening right now is that if you join, the room must be full before it starts, and that is what is happening. What I want now is to display how many people have joined the current room using UI on the matchmaker panel. How could I do this. If any scripts or info is needed, please ask! Thanks.
     
  2. PutridEx

    PutridEx

    Joined:
    Feb 3, 2021
    Posts:
    1,136
    PhotonNetwork.CurrentRoom.PlayerCount
    It's updated every 5 seconds by master-server.
     
  3. Johan_Liebert123

    Johan_Liebert123

    Joined:
    Apr 15, 2021
    Posts:
    474
    thanks for your reply. That does seem to be the answer, I've tried a couple of way to use that but I'm unable to get it working. Could I get some assistance on how to use that to display text?
     
  4. PutridEx

    PutridEx

    Joined:
    Feb 3, 2021
    Posts:
    1,136
    It's an integer, you need to convert it to a string.
    string playerCount = PhotonNetwork.CurrentRoom.PlayerCount.toString();
    then use playerCount, you'll need to reassign it to get the updated playerCount.
    or just use PhotonNetwork.CurrentRoom.PlayerCount.toString()
    should work
     
  5. Johan_Liebert123

    Johan_Liebert123

    Joined:
    Apr 15, 2021
    Posts:
    474
    Something like this
    Code (CSharp):
    1. public override void OnConnectedToMaster()
    2.     {
    3.         base.OnConnectedToMaster();
    4.  
    5.         if (isConnecting)
    6.         {
    7.             PhotonNetwork.JoinRandomRoom();
    8.             PlayersInRoom.text = PhotonNetwork.CurrentRoom.PlayerCount.ToString();
    9.         }
    10.     }
     
  6. PutridEx

    PutridEx

    Joined:
    Feb 3, 2021
    Posts:
    1,136
    No, better to call it onRoomJoined callback (not the exact name of the callback, forgot), been a while since I used pun but there's a callback for that.