How to display the PhotonNetwork.playerList as a ranking?
Options
JannickL
✭
Cheers guys and happy new year
What's the recommended way to get a player custom property and print every player ranked using photon networks player list?
I'd try something like this but I cannot figure out how to code that the score get's ranked and displayed in the correct order? :
What's the recommended way to get a player custom property and print every player ranked using photon networks player list?
I'd try something like this but I cannot figure out how to code that the score get's ranked and displayed in the correct order? :
void DisplayRanking() { foreach (PhotonPlayer player in PhotonNetwork.playerList) { int score = (int)player.CustomProperties["score"]; // but how to code that the score now get's ranked and displayed in the correct order? display.text += (player.NickName + " Score: " + player.CustomProperties["score"] + " \n"); } }Greets
0
Comments
-
No one?0
-
@JannickL you could try Linq for sorting, something like this:
using System.Linq; void DisplayRanking(){ var leaderboard = from p in PhotonNetwork.playerList orderby (int) p.CustomProperties["score"] descending select p; foreach(var player in leaderboard) { int score = (int)player.CustomProperties["score"]; display.text += string.Format("{0} Score: {1}\n", player.NickName, score); } }
0