我试图将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
}
}
答案 0 :(得分:4)
要显示iOS游戏中心排行榜,您需要使用GameCenterPlatform。
您的代码将是:
void ShowLeaderboard() {
#if UNITY_IOS
GameCenterPlatform.ShowLeaderboardUI(leaderboardId, UnityEngine.SocialPlatforms.TimeScope.AllTime);
#endif
}
答案 1 :(得分:0)
实际上现在你甚至不需要获得GameCenterPlatforms。您只需使用Social
即可。等。
public void OnLeaderboard()
{
// Checking if user already authenticated or not.
if (Social.localUser.authenticated)
Social.ShowAchievementsUI ();
else
// If not then authenticate first then show Leaderboard
Social.localUser.Authenticate ((bool success) => {
// handle success or failure
if (success)
Social.ShowAchievementsUI ();
});
}
}