无法在iOS版Unity游戏中调用GameCenter

Dan*_*iel 2 c# game-engine unity-game-engine game-center-leaderboard unity5

我试图将Game Center集成到我的Unity 5项目中,并且遇到了麻烦。似乎在iOS设备上启动游戏时,身份验证正常,出现通知,但页首横幅按钮不起作用,当我点击GC按钮时什么也没有发生。我将“ ShowLeaderboard()”的启动分配给了GC按钮。请看下面我使用的脚本。希望为我的问题找到解决方案。先感谢您。

using UnityEngine;
using UnityEngine.SocialPlatforms;
using UnityEngine.SocialPlatforms.GameCenter;
using System.Collections;

public class GameCenter : MonoBehaviour {

    public string leaderboardID = "mygameleaderboard";

    void Start () {
        AuthenticateToGameCenter();
    }

    private bool isAuthenticatedToGameCenter;
    public static void  AuthenticateToGameCenter() {
        #if UNITY_IPHONE
        Social.localUser.Authenticate(success => {
        if (success) {
            Debug.Log("Authentication successful");
        } else {
            Debug.Log("Authentication failed");
            }
        });
        #endif
    }

    public static void ReportScore(long score, string leaderboardID) {
        #if UNITY_IPHONE
        Debug.Log("Reporting score " + score + " on leaderboard " + leaderboardID);
        Social.ReportScore(score, leaderboardID, success => {
            if (success) {
            Debug.Log("Reported score successfully");
            } else {
                Debug.Log("Failed to report score");
                }
            });
        #endif
    }

    //call to show leaderboard
    public static void ShowLeaderboard() {
        #if UNITY_IPHONE
        Social.ShowLeaderboardUI();
        #endif
    }
}
Run Code Online (Sandbox Code Playgroud)

Jay*_*ani 5

要显示iOS Game Center排行榜,您需要使用GameCenterPlatform

您的代码将是:

void ShowLeaderboard() {
    #if UNITY_IOS
    GameCenterPlatform.ShowLeaderboardUI(leaderboardId, UnityEngine.SocialPlatforms.TimeScope.AllTime);
    #endif
}
Run Code Online (Sandbox Code Playgroud)