Pun 2 ranking list?

I am trying to make a simple ranking list. Every player has different progress, but I want that player can see other players' progress on list. Idea is that a text tells first player's progress, b text tells second player's progress etc. There is no errors but code just does nothing(not even print debug.log). This code may be completely wrong but since I am really noob with Pun and it's really hard to find clear, up to date(pun 2) tutorials for my needs, I would really appreciate if someone told me what I'm doing wrong.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine.UI;

public class RankManager : MonoBehaviour, IPunObservable
{
    public Text a;
    public Text b;
    public Text c;

    public PhotonView photonView;

    private Player[] players;

    private float progress;

    void Update()
    {

        if(photonView.IsMine)
        {
            progress = YourStats.progress;
        }

        

        players = PhotonNetwork.PlayerList;
        for(int x = 0; x < players.Length; x++)
        {
            a.text = players[0].CustomProperties[progress].ToString();
            b.text = players[1].CustomProperties[progress].ToString();
            c.text = players[2].CustomProperties[progress].ToString();

            Debug.Log("Hello");
        }

    }

    void IPunObservable.OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        if (stream.IsWriting)
        {
            stream.SendNext(a.text);
            stream.SendNext(b.text);
            stream.SendNext(c.text);
        }
        else
        {
            a.text = (string)stream.ReceiveNext();
            b.text = (string)stream.ReceiveNext();
            c.text = (string)stream.ReceiveNext();
        }
    }
}

Answers

  • BbHBbH
    edited May 10
    Samuli wrote: »
    I am trying to make a simple ranking list. Every player has different progress, but I want that player can see other players' progress on list. Idea is that a text tells first player's progress, b text tells second player's progress etc. There is no errors but code just does nothing(not even print debug.log). This code may be completely wrong but since I am really noob with Pun and it's really hard to find clear, up to date(pun 2) tutorials for my needs, I would really appreciate if someone told me what I'm doing wrong.
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using Photon.Pun;
    using Photon.Realtime;
    using UnityEngine.UI;
    
    public class RankManager : MonoBehaviour, IPunObservable
    {
        public Text a;
        public Text b;
        public Text c;
    
        public PhotonView photonView;
    
        private Player[] players;
    
        private float progress;
    
        void Update()
        {
    
            if(photonView.IsMine)
            {
                progress = YourStats.progress;
            }
    
            
    
            players = PhotonNetwork.PlayerList;
            for(int x = 0; x < players.Length; x++)
            {
                a.text = players[0].CustomProperties[progress].ToString();
                b.text = players[1].CustomProperties[progress].ToString();
                c.text = players[2].CustomProperties[progress].ToString();
    
                Debug.Log("Hello");
            }
    
        }
    
        void IPunObservable.OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
        {
            if (stream.IsWriting)
            {
                stream.SendNext(a.text);
                stream.SendNext(b.text);
                stream.SendNext(c.text);
            }
            else
            {
                a.text = (string)stream.ReceiveNext();
                b.text = (string)stream.ReceiveNext();
                c.text = (string)stream.ReceiveNext();
            }
        }
    }
    


    Don't know if you are still looking, but here is something I have done in my game:

    Basically, after the game ends each player sends his kills/deaths value to the master client using RPC, who saves the data in each player's custom properties using PhotonNetwork.PlayerList and PhotonNetwork.NickName(assign unique nickname to each player when they join room). Master client then creates another list ("leaderboard in code") using the playerList accordingly(ascending/descending order) and then displays it. Do use using System.Linq.

    https://drive.google.com/file/d/1rnY1S1WbepLMZftg1rJaUr36pBWEhHQQ/view?usp=sharing
Sign In or Register to comment.