【问题标题】:Getting error when attempting to save score?尝试保存分数时出错?
【发布时间】:2016-07-21 16:22:18
【问题描述】:

以下代码从 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();
                }
            });
}

不幸的是,我在这一行遇到了 2 个错误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'

我该如何解决这个问题?

【问题讨论】:

  • 您是否尝试过将 long 显式转换为 int?

标签: c# unity3d


【解决方案1】:

您必须将data.Scores[0].value(即long)转换为Integer

你可以像这样又快又脏:

PlayerPrefs.SetInt("highScore", (int)data.Scores[0].value);

【讨论】:

  • 谢谢。错误消失了,但没有保存新的排行榜分数。你知道为什么吗?
  • 你调试过,确定发送到服务器的值是正确的吗?
  • 别担心。我修好了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-09-05
  • 1970-01-01
  • 1970-01-01
  • 2014-12-28
  • 2017-08-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多