【发布时间】:2021-08-11 21:50:42
【问题描述】:
我的 Google Play 服务排行榜有问题,我已经卡了好几天了。
我正在使用Play Games Plugin for Unity。
我正在尝试获取特定级别的 Userrank。因此,我通过 LoadScores 函数加载分数,这似乎工作正常。
问题似乎是,我在“LoadScores”函数中获得了正确的排名,但整体 GetUserRank 函数仍然返回 rank = 0,无论实际的 Userrank 是什么。
我的猜测是,这毕竟是一个时间问题,并且在 LoadScores 函数计算要返回的正确排名之前返回排名。
public int GetUserRank(string levelID)
{
int rank = 0;
string user = PlayGamesPlatform.Instance.localUser.id;
string leaderboard = ReturnLeaderboard(levelID);
Social.LoadScores(leaderboard, scores =>
{
if (scores.Length > 0)
{
Debug.Log("Retrieved " + scores.Length + " scores");
//Filter the score with the user name
for (int i = 0; i < scores.Length; i++)
{
if (user == scores[i].userID)
{
rank = scores[i].rank;
// This prints out the actual rank of the user and seems to work
print("Rank in LoadScoresFunction: " + rank);
break;
}
}
}
else
Debug.Log("Failed to retrieved score");
});
//Here the rank is always 0, no matter the outcome of the LoadScores Function above
print("Rank in PlayGamesController: " + rank);
return rank;
}
我通过以下方式从其他脚本中引用此函数:
int rank = PlayGamesController.Instance.GetUserRank(levelID);
非常感谢任何想法/提示。
谢谢!
【问题讨论】:
标签: c# unity3d google-play-services leaderboard