【发布时间】:2016-01-27 08:31:10
【问题描述】:
我正在尝试将 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
}
}
【问题讨论】:
-
我个人使用 Prime31 插件专门用于 Unity 和 GameCenter 集成。它通过漂亮的界面整齐地放置社交平台的所有内容和摘要。 prime31.com
标签: c# unity3d game-engine unity5 game-center-leaderboard