Leaderboards

Enhance competitiveness by integrating leaderboards, allowing players to compare their scores and achievements.

Support

Use this to determine if you can implement leaderboards for your game on the current platform.

Bridge.leaderboard.isSupported

Player Scores. Set

Submit the player's score to the leaderboard to update their rank and position.

private void Start()
{
    var options = new Dictionary<string, object>();

    switch (Bridge.platform.id)
    {
        case "yandex":
            options.Add("score", 42);
            options.Add("leaderboardName", "YOUR_LEADERBOARD_NAME");
            break;
    }

    Bridge.leaderboard.SetScore(options, OnSetScoreCompleted);
}

private void OnSetScoreCompleted(bool success)
{
    if (success)
    {
        // Operation succeeded
    }
    else
    {
        // An error occurred
    }
}

Player Scores. Get

Retrieve the player's score from the leaderboard to display their current standing.

private void Start()
{
    var options = new Dictionary<string, object>();

    switch (Bridge.platform.id)
    {
        case "yandex":
            options.Add("leaderboardName", "YOUR_LEADERBOARD_NAME");
            break;
    }

    Bridge.leaderboard.GetScore(options, OnGetScoreCompleted);
}

private void OnGetScoreCompleted(bool success, int score)
{
    if (success)
    {
        // Data successfully retrieved
        Debug.Log(score);
    }
    else
    {
        // Something went wrong
    }
}

Get Full Leaderboard

Retrieve entries from the leaderboard, including the player's rank and score, to display a comprehensive leaderboard.

private void Start()
{
    var options = new Dictionary<string, object>();

    switch (Bridge.platform.id)
    {
        case "yandex":
            options.Add("leaderboardName", "YOUR_LEADERBOARD_NAME");
            options.Add("includeUser", true);
            options.Add("quantityAround", 10);
            options.Add("quantityTop", 10);
            break;
    }

    Bridge.leaderboard.GetEntries(options, OnGetEntriesCompleted);
}

private void OnGetEntriesCompleted(bool success, List<Dictionary<string, string>> entries)
{
    Debug.Log($"OnGetEntriesCompleted, success: {success}, entries:");
    
    if (success)
    {
        switch (Bridge.platform.id)
        {
            case "yandex":
                foreach (var entry in entries)
                {
                    Debug.Log("ID: " + entry["id"]);
                    Debug.Log("Score: " + entry["score"]);
                    Debug.Log("Rank: " + entry["rank"]);
                    Debug.Log("Name: " + entry["name"]);
                    Debug.Log("Photo: " + entry["photo"]);
                }
                break;
        }
    }
}

Last updated