为什么Social.ReportScore不适用于此脚本?

时间:2016-02-07 15:11:12

标签: c# unity3d scripting google-play-services google-play-games

我制作了这个简单的脚本,将分数发布到Google Play排行榜。我知道我输入了排行榜代码,因为它显示了排行榜的名称。然而,它不是显示54321的分数,而是说“成为第一个上传分数的人!”。这个脚本有什么问题?我花了几个小时在网上看,但似乎我做的一切都正确!谢谢你

using UnityEngine;
 using System.Collections;
 using GooglePlayGames;
 using UnityEngine.SocialPlatforms;

 public class PlayGames: MonoBehaviour {

 // Use this for initialization
 void Start () 
{
    PlayGamesPlatform.Activate();
    //PlayGamesPlatform.Instance.Authenticate; not working get error CS0201: 
    //Only assignment, call, inrement, decrement, and new oject expressions can be used as a statement.
    //so I'm trying to get this to work with a bool
    PlayGamesPlatform.Instance.Authenticate((bool success) => {
        //hope this works!
    });
    if (!PlayGamesPlatform.Instance.localUser.authenticated)
    {
        return;
    }
    PlayGamesPlatform.Instance.ReportScore(543210,"Cgglqe3m-mcQAhAI", (bool success) =>
        {
            if (success)
            {
                Social.ShowLeaderboardUI();
                Debug.Log("log to leaderboard succeeded");
            }
            else
            {
                Debug.Log("log to leaderboard failed");
            }
        });

}
}

1 个答案:

答案 0 :(得分:0)

在设备上进行调试时,您是否在某个时刻看到了日志? 请注意ReportScore是异步调用

只是为了确定,请尝试以下代码:

Social.ReportScore (54321, "Cgglqe3m-mcQAhAI", 
  success => 
{
   Social.ShowLeaderboardUI ();
});

修改

这对我有用: 在代码中调用PlayGamesPlatform.Activate();一次。 之后,请致电PlayGamesPlatform.Instance.Authenticate。 当我想记录得分时,我用这个:

    public static void LogScoreInGameService(int score, string leaderBoard)
    {
        if (!PlayGamesPlatform.Instance.localUser.authenticated)
        {
            return;
        }
        PlayGamesPlatform.Instance.ReportScore(score, leaderBoard, (bool success) =>
        {
            if (success)
            {
                Debug.Log("log to leaderboard succeeded");
            }
            else
            {
                Debug.Log("log to leaderboard failed");
            }
        });
    }