My static variables are not working with Photon

So I have an issue with Photon. I am trying to make each player's own separate rank display on the scoreboard of the room. What happens right now? Well it is currently showing the local player's rank amongst all others players and vise versa on the that other player's rank. For example if your playing my game on your local machine and your rank is 2 then all the other player's ranks will show 2 on their names in the room...

Script 1 - Main Menu
Here's my variable -
public static int rank_number;

Script 2 - Scoreboard

GUILayout.Label("Rank " + (int)ConnectMenu.rank_number);
//Display player name
GUILayout.BeginHorizontal();
if(teamTmp[i].customProperties["PlayerHP"] == null || (int)teamTmp[i].customProperties["PlayerHP"] < 1){
GUI.color = GameSettings.customRedColor;
GUILayout.Label("*");
GUILayout.Space(5);
}

GUI.color = (int)teamTmp[i].customProperties["Team"] == 1 ? GameSettings.teamAColor : GameSettings.teamBColor;
playerRank = ConnectMenu.currentRank;
GUILayout.Label(teamTmp[i].name);


Do I need customProperties set?
Let me know if you have any idea of a fix please :)

Comments

  • Hi @aidangig,

    Do I need customProperties set?


    You don't have to, but it makes things much easier if you use Custom Player Properties. To set this property for the local client, you can use the following code snippet:
    Hashtable props = new Hashtable { { "rank", 1 } }; // replace '1' with the actual rank
    PhotonNetwork.player.SetCustomProperties(props);
    To get this information, you can iterate through PhotonNetwork.playerList and access the properties like this:
    foreach (PhotonPlayer p in PhotonNetwork.playerList)
    {
        int rank = (int)p.CustomProperties["rank"];
    
        // add further logic
    }
    For handling teams you can also take a look at PunTeams which extends the PhotonPlayer with options for setting and getting the current team. Therefore the local client can use PhotonNetwork.player.SetTeam(PunTeams.Team.blue); or PhotonNetwork.player.GetTeam();.