我想获得的利用光子统一网络在多人模式中玩家的分数。
PhotonNetwork.playerList[i].GetScore();
我用上面的线来获得在当前房间中所有玩家的分数。
我增加了球员的名字和分数像这样一本字典,1。玩家名称为“关键”。 2.球员得分为“价值”。
for(int i = 0; i < PhotonNetwork.playerList.Length; i++)
{
if (dict.ContainsKey (PhotonNetwork.playerList[i].name))
{
dict[PhotonNetwork.playerList[i].name] = PhotonNetwork.playerList[i].GetScore();
}
else
{
dict.Add (PhotonNetwork.playerList[i].name, PhotonNetwork.playerList[i].GetScore());
}
}
在此之后,我想前5分和降序的名称。所以,我整理了字典,并采取了前5个值这样,
foreach(var item in dict.OrderByDescending(r => r.Value).Take(5))
{
scoreText.text = item.Key +" "+ item.Value;
}
所需的输出是“在字典中的分类5个元素”请帮我找到解决方案。谢谢。
你可以用下面这行代码:
var sortedPlayerList = (from p in playerList orderby p.GetMyScore() descending select p).ToList();
它会用排序从高到低的数组,可以显示前5名的球员是这样的:
for(int i = 0; i < 5; i++) {
// show your player's score
}