[Pun2] Score system

I am trying to make something like a scoreboard, but I don’t know how. I tried to start by adding new players to a list, but the problem is when a new player joins, they don’t have the updated version of the list. please help

public class ScoreManager : MonoBehaviourPun
{
    public PhotonView view;

    public TextMeshProUGUI player1Text;

    List<Player> players = new List<Player>();

    void Start()
    {
        view = GetComponent<PhotonView>();
    }
 
    [PunRPC]
    public void CreatePlayer(int _index)
    {
        players.Add(new Player(_index, 0));
        Debug.Log("list length" + players.Count);
        player1Text.text = players[_index].kills.ToString();
    }

    [PunRPC]
    public void UpdatePlayerKills(int _index)
    {
        for (int i = 0; i < players.Count; i++)
        {
            if(players[i].index == _index)
            {
                players[i].kills += 1;
            }
        }
    }

}

You can instantiate a score item for each prefab, make a script for the score item prefab, and set the stats accordingly
Your list doesnt update because you probably dont run it in update, or call it in the callback OnPlaterEnteredRoom, doing 1 of those should do the job

New players somehow should get the actual version of the list when they join the room

When they join them to the room, add them to the list

How? right now I have a script attached to the player and in the Start() function I call this:

IEnumerator SetMyName()
    {
        yield return new WaitForSeconds(1f);
        if (view.IsMine)
        {
            int index = PlayerNumberingExtensions.GetPlayerNumber(PhotonNetwork.LocalPlayer);
            Debug.Log(index);
            scoreManager.view.RPC("CreatePlayer", RpcTarget.All, index);
        }
    }

Thats just setting their name, here’s what you should do

  1. Create a list of players
  2. In the OnJoinedRoom callback, add player to the list
  3. Create a method which displays the list and call it in Update()

I don’t understand the last step

If you want to instantiate a GO for each player

for(int i = 0; i < players.Count; i++)
{
       Instantiate(playerItem, content);
}

Your not really telling me what you are trying to achieve, please make your objective more clear!

My game is like shooting game, I want to keep track of how many kills each player has

You’ll have to use custom properties for that, whenever player joins a room, set their custom properties of kills to 0, every time they get a kill, add 1 to it

It’s been a while but can you help me please, I can’t figure out how to use custom properties