Enhance competitiveness by integrating leaderboards, allowing players to compare their scores and achievements.
Use this to determine if you can implement leaderboards for your game on the current platform.
Bridge.leaderboard.isSupported
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;
case "facebook":
options.Add("score", 42);
options.Add("leaderboardName", "YOUR_LEADERBOARD_NAME");
break;
case "lagged":
options.Add("score", 42);
options.Add("boardId", "YOUR_LEADERBOARD_ID");
break;
}
Bridge.leaderboard.SetScore(options, OnSetScoreCompleted);
}
private void OnSetScoreCompleted(bool success)
{
if (success)
{
// Operation succeeded
}
else
{
// An error occurred
}
}
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;
case "facebook":
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
}
}
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;
case "facebook":
options.Add("leaderboardName", "YOUR_LEADERBOARD_NAME");
options.Add("count", 10);
options.Add("offset", 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;
case "facebook":
foreach (var entry in entries)
{
Debug.Log("ID: " + entry["playerId"]);
Debug.Log("Score: " + entry["score"]);
Debug.Log("Rank: " + entry["rank"]);
Debug.Log("Name: " + entry["playerName"]);
Debug.Log("Photo: " + entry["playerPhoto"]);
}
break;
}
}
}