- Home /
Can't call GameCenter in my Unity game for iOS
Hello! I'm trying to integrate Game Center into my Unity 5 project and facings troubles. It seems that authentification is OK when the game starts on iOS device, a notification appears, but leaderboard button does not work, nothing happens when I tap GC button. I assigned the initiation of "ShowLeaderboard()" to GC button. Please, take a look at the script I use below. Hope to find a resolution for my issue. Thank you in advance.
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
}
}
Well, your script should work... maybe try with Social.Active.Show$$anonymous$$erboardUI();
ins$$anonymous$$d ? The Social module on iOS is actually very buggy (especially with achievements), but Show$$anonymous$$erboardUI should work flawlessly. Anything suspicious in the logs ?
Your answer
Follow this Question
Related Questions
Gamecenter leaderboards? 1 Answer
MarshalAs UnmanagedType.LPArray always returns with array of size 1 in iOS 0 Answers
Game Center login issue 0 Answers
DateTime.now not working on iOS 0 Answers
Did Social.LoadUsers() stop working? 3 Answers