Add a new score
To add or update an entry for the player in the specified leaderboard, use the AddPlayerScoreAsync
method.
public async void AddScore(string leaderboardId, int score)
{
var playerEntry = await LeaderboardsService.Instance
.AddPlayerScoreAsync(leaderboardId, score);
Debug.Log(JsonConvert.SerializeObject(playerEntry));
}
Add a new score with metadata
To add a score with metadata, use the Metadata
option on the AddPlayerScoreOptions
configuration object:
[Serializable]
public class ScoreMetadata
{
public string levelName;
public int timeTaken;
}
public async void AddScoreWithMetadata(string leaderboardId, int score)
{
var scoreMetadata = new ScoreMetadata { levelName = "LEVEL_01", timeTaken = 120 };
var playerEntry = await LeaderboardsService.Instance
.AddPlayerScoreAsync(
leaderboardId,
score,
new AddPlayerScoreOptions { Metadata = scoreMetadata }
);
Debug.Log(JsonConvert.SerializeObject(playerEntry));
}
If a score that has stored metadata is updated with null metadata, the new metadata value will be null.