- Home /
iOS: Game Center show leaderboard with only my score ?
Hi, i'm making a leadearboard using with Game Center now, and i have 2 questions:
static ILeaderboard m_Leaderboard;
private int highScore = 1000;
private string leaderboardName = "Test Ranking";
private string leaderboardID = "55612367";
// private string achievementName = "70215624";
// Use this for initialization
void Start () {
Social.localUser.Authenticate (ProcessAuthentication);
}
public void SendAndShow(){
ReportScore(highScore, leaderboardID);
DoLeaderboard();
}
///////////////////////////////////////////////////
// INITAL AUTHENTICATION (MUST BE DONE FIRST)
///////////////////////////////////////////////////
// THIS FUNCTION GETS CALLED WHEN AUTHENTICATION COMPLETES
// NOTE THAT IF THE OPERATION IS SUCCESSFUL Social.localUser WILL CONTAIN DATA FROM THE GAME CENTER SERVER
void ProcessAuthentication (bool success) {
if (success) {
Debug.Log ("Authenticated, checking achievements");
Social.LoadScores(leaderboardName, scores => {
if (scores.Length > 0) {
// SHOW THE SCORES RECEIVED
Debug.Log ("Received " + scores.Length + " scores");
string myScores = "Leaderboard: \n";
foreach (IScore score in scores)
myScores += "\t" + score.userID + " " + score.formattedValue + " " + score.date + "\n";
Debug.Log (myScores);
}
else
Debug.Log ("No scores have been loaded.");
});
}
else
Debug.Log ("Failed to authenticate with Game Center.");
}
#region Game Center Integration
///////////////////////////////////////////////////
// GAME CENTER LEADERBOARD INTEGRATION
///////////////////////////////////////////////////
/// <summary>
/// Reports the score to the leaderboards.
/// </summary>
/// <param name="score">Score.</param>
/// <param name="leaderboardID">Leaderboard I.</param>
void ReportScore (long score, string leaderboardID) {
Debug.Log ("Reporting score " + score + " on leaderboard " + leaderboardID);
Social.ReportScore (score, leaderboardID, success => {
Debug.Log(success ? "Reported score to leaderboard successfully" : "Failed to report score");
});
}
/// <summary>
/// Get the leaderboard.
/// </summary>
void DoLeaderboard () {
m_Leaderboard = Social.CreateLeaderboard();
m_Leaderboard.id = leaderboardID; // YOUR CUSTOM LEADERBOARD NAME
m_Leaderboard.LoadScores(result => DidLoadLeaderboard(result));
}
/// <summary>
/// RETURNS THE NUMBER OF LEADERBOARD SCORES THAT WERE RECEIVED BY THE APP
/// </summary>
/// <param name="result">If set to <c>true</c> result.</param>
void DidLoadLeaderboard (bool result) {
Debug.Log("Received " + m_Leaderboard.scores.Length + " scores");
foreach (IScore score in m_Leaderboard.scores) {
Debug.Log(score);
}
Social.ShowLeaderboardUI();
}
#endregion
i get the Leaderboard ID in iTune is 55612367 (and the name of Leaderboard ID is "com.test.ranking"), and when i build and run app, it show "No score" or "No leadboard". But when i replace ID "55612367" to "com.test.ranking", it show leadboard with my score. Please explain me about it ?
i use 2 account sandbox testers to test in 2 devices, but each device couldn't see each other's score. So how can i see other people's score in my leaderboard ?
Comment