THIS CONTENT DOWNLOAD SHORTLY

Objective

Complete walk through of how to setup leaderboard in Unity for iOS.

 

 

Step 1 Create An App

Create an app on iTunesConnect - http://itunesconnect.apple.com/

 

Step 2 Create a Leaderboard

Create a leaderboard in app on iTunesConnect

 

Step 3 Get Leaderboard

Get the Leaderboard ID from the app on iTunesConnect

 

Step 4 LeaderboardManager Script

Create a script named – LeaderboardManager

Put this code in it

public class LeaderboardManager : MonoBehaviour
{
    #region GAME_CENTER    
    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");
            }
 
            Debug.Log(success ? "Reported score successfully" : "Failed to report score"); Debug.Log("New Score:"+score);  
        });
        #endif
    }
    
    public static void ShowLeaderboard()
    {
        #if UNITY_IPHONE
            Social.ShowLeaderboardUI();
        #endif
    }
    #endregion
}
 

Step 5 Create Script For UI

Create another Script for UI and use your Leaderboard ID in it.

#region PRIVATE_VARIABLES
 
    string leaderBoardID = "PROVIDE_YOUR_LEADERBOARD_ID_HERE";
 
    #endregion
 
    #region BUTTON_EVENT_HANDLER
 
    /// <summary>
    /// Raises the login event.
    /// </summary>
    /// <param name="id">Identifier.</param>
    public void OnLogin(string id){
        LeaderboardManager.AuthenticateToGameCenter();
    }
 
    /// <summary>
    /// Raises the show leaderboard event.
    /// </summary>
    public void OnShowLeaderboard(){
        LeaderboardManager.ShowLeaderboard();
    }
 
    /// <summary>
    /// Raises the post score event.
    /// </summary>
    public void OnPostScore(){
        LeaderboardManager.ReportScore(100,leaderBoardID);
    }
 
    #endregion
 

Step 6 Snaps

 

6.1 UI

ui

 

6.2 Sign-In UI

sign-in-ui

 

6.3 After Sign-In

after-sign-in

 

6.4 Leaderboard UI

leaderboard-ui

I hope you find this blog post helpful while setting up leaderboard for iOS in Unity. Let me know if you have any questions or concerns regarding leaderboard setup for iOS or leaderboard setup in unity. Please put a comment here and we will get back to you ASAP. Thanks.

Got an Idea of Game Development? What are you still waiting for? Contact us now and see the Idea live soon. Our company has been named as one of the best Game Development Company in India.

I'm a Professional Game Developer, truly passionate about creating different types of games and learning different gaming concepts that can enhance my knowledge. Games are my passion and I aim to create addictive, unique, creative and high quality games.

face mask Belial The Demon Headgear Pocket Staff Magic