【问题标题】:Why isn't Social.ReportScore working in this script?为什么 Social.ReportScore 在此脚本中不起作用?
【发布时间】:2016-05-17 06:15:09
【问题描述】:

我制作了这个简单的脚本来将分数发布到 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");
            }
        });

}
}

【问题讨论】:

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


    【解决方案1】:

    在设备上进行调试时,您是否看到过日志? 考虑到 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");
                }
            });
        }
    

    【讨论】:

    • 我试过你的脚本,同样的事情。我第一次打开排行榜场景时,它让我登录。第二次打开排行榜但要求我成为第一个发布分数的人。如何从设备查看调试日志?谢谢!
    • 再次感谢您的帮助,但它仍然没有使用我制作的新脚本发布分数(显示在我的问题中)。可能有什么问题?
    • 我建议您首先检查您的配置是否正确。从您的问题中,我看到您使用 Unity,您应该将开发人员控制台中的资源添加到 Unity。您还应该在开发者控制台中检查您的排行榜可用,并且它可以接收 int 作为有效值。之后,将日志添加到您的代码中以查看失败的地方。无论如何,请务必按照此处的说明进行操作:github.com/playgameservices/play-games-plugin-for-unity,这是 google play 服务的 git repo(或者您可以在 google 上搜索)
    • 您找到问题了吗?
    • 我通过完全重置所有可以重置的东西来修复它。所以我加载了一个新的 .APK,创建了新的排行榜、新的密钥库等……现在似乎可以正常工作了!
    猜你喜欢
    • 2019-11-12
    • 1970-01-01
    • 2013-05-23
    • 2021-09-15
    • 2013-11-18
    • 1970-01-01
    • 2018-03-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多