PunRPC - Updating the UI in a lobby (doing something wrong)

Options
So the UI has a list of players. Let's say it defaults to say "0" for the # of players.

Whenever a player joins the lobby, I want EVERYONE's UI to also read numOfPlayers++.

So the master client (M) joins, total players 1.
Another client (C) joins, total players 2.

Right now, I'm trying this (and it doesn't seem to work):
public override void OnJoinedRoom() 
{
    base.OnJoinedRoom();
    RpcUpdatePlayerUI();
}

[PunRPC]
void RpcUpdatePlayerUI()
{
    int playerCount = PhotonNetwork.room.PlayerCount;
    playerCountTxt.text = playerCount.ToString();
}
Results:
M = 1
C = 2

My guess is that Cwasn't a master client, so it didn't have permission to Rpc to the others, so it only assigned itself.

So with UNET, I could just [Command] to talk to the host to Rpc to others. How would I do the equiv. in Photon?

Comments

  • JohnTube
    JohnTube ✭✭✭✭✭
    edited January 2017
    Options
    Hi @xblade724,

    two things:
    1. I do not think that there is a need to override OnJoinedRoom.
    2. I do not think that there is a need to use a PunRPC to synchronize players count UI! You just need to know when the players count is being updated every time. You can do this like this:
    
    // another player has joined
    void OnPhotonPlayerConnected(PhotonPlayer newPlayer){
        UpdatePlayersCountText();
    }
    
    // local player has joined
    void OnJoinedRoom(){
        UpdatePlayersCountText();
    }	
    
    void UpdatePlayersCountText(){
        int playerCount = PhotonNetwork.room.PlayerCount;
        playerCountTxt.text = playerCount.ToString();
    }
  • xblade724
    Options
    Ahh this gives me a lot to work with, thanks ;D