android - Google Play 服务 Unity 插件不显示排行榜

标签 android unity-game-engine google-play-services google-play-games

我正在使用 Unity 5 为 Android 构建游戏,我已经导入了这个 plugin

但它不能正常工作我按照这个tutorial :

当我尝试发布或显示排行榜时,它没有显示任何内容。它甚至没有抛出任何错误。登录和注销工作正常。请帮忙

代码:

public void LogIn ()
{
    Social.localUser.Authenticate ((bool success) =>
    {
        if (success) {
            Debug.Log ("Login Sucess");
        } else {
            Debug.Log ("Login failed");
        }
    });
}

public void LogOut ()
{
    PlayGamesPlatform.Instance.SignOut ();
}

public void Post ()
{

    if (Social.localUser.authenticated) {
        Social.ReportScore (5000, LeaderbordId, (bool success) =>
        {
            if (success) {
                ((PlayGamesPlatform)Social.Active).ShowLeaderboardUI (LeaderbordId);
            } else {
                Debug.Log ("Add Score Fail");
            }
        });
    } 
}

public void ShowLeader ()
{

    Social.ShowLeaderboardUI ();
}

最佳答案

我不确定我是否得到了你想要的。我认为您每次发布分数时都试图打开排行榜。我将更改您的脚本以使其更易于理解。

当您使用 Google Play 服务插件时,您需要做一些事情才能开始。确保你有这个。在脚本的顶部,您将编写:

using GooglePlayGames;
using UnityEngine.SocialPlatforms;

然后你需要将它添加到你的启动函数中:

void Start(){
    PlayGamesPlatform.Activate();
}

如果你做一个函数只是为了显示你的排行榜,那就更容易了,比如你的最后一个函数:

public void ShowLB(){
    ((PlayGamesPlatform) Social.Active).ShowLeaderboardUI("YOUR_LEADERBOARDS_ID_HERE");
}

那么你的 Post() 函数应该是这样的:

public void Post (){

    if (Social.localUser.authenticated) {
        Social.ReportScore (5000, LeaderbordId, (bool success) =>
        {
            if (success) {
                ShowLB ();
            } else {
                Debug.Log ("Add Score Fail");
            }
        });
    } 
}

在你的最后一个函数中你可能想要这样做:

public void ShowAchievs(){
    Social.ShowAchievementsUI ();
}

否则应该是这样的:

public void ShowLB(){
    ((PlayGamesPlatform) Social.Active).ShowLeaderboardUI("YOUR_LEADERBOARDS_ID_HERE");
}

但是,如果您只是在触发后使用发布功能(例如游戏结束)并使用其他东西来显示您的 LB,那就简单多了。就像点击按钮或其他东西。

我不知道那是你想要的。

关于android - Google Play 服务 Unity 插件不显示排行榜,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31372479/

相关文章:

unity-game-engine - 力场着色器展开纹理不起作用

c# - Hololens 2 轻击和头部移动在 Unity 中有效,但在 HoloLens 上无效

android - 将 Android Play 服务包含到 APK

java - 如何动态加载 R.styleable 资源?

java - 返回新的 AndroidMusic()

java - Android 无法在表面 View 中切换到前置摄像头

android - 如何从 Google Playstore 获取最新版本的 Android 应用程序?

java - 找不到类 'android.os.PersistableBundle'

c# - 2D Portal 有时只能在 Unity 中工作

android - 使用最后一个 google play 服务 api 位置停止位置更新