以下代码从Google Play排行榜中检索玩家的得分。如果检索到的值优于已存储在设备上的值,则保存分数。
public void Update()
{
PlayGamesPlatform.Instance.LoadScores(
"myLeaderboardID",
LeaderboardStart.PlayerCentered,
100,
LeaderboardCollection.Public,
LeaderboardTimeSpan.AllTime,
(data) =>
{
if (data.Valid)
if (data.Scores[0].value > PlayerPrefs.GetInt("highScore", highScore))
{
PlayerPrefs.SetInt("highScore", data.Scores[0].value);
PlayerPrefs.Save();
}
});
}
不幸的是,我在这一行PlayerPrefs.SetInt("highScore", data.Scores[0].value);
error CS1502: The best overloaded method match for `UnityEngine.PlayerPrefs.SetInt(string, int)' has some invalid arguments
error CS1503: Argument `#2' cannot convert `long' expression to type `int'
我该如何解决这个问题?
答案 0 :(得分:1)
您必须将data.Scores[0].value
(long
)投射到Integer
你可以像这样快速而肮脏:
PlayerPrefs.SetInt("highScore", (int)data.Scores[0].value);