PlayFab: Load Current Users PlayFab Leaderboard Score in Unity with C#

3/17/2021 5:06:02 PM

Load the current users PlayFab top score(s) in Unity with C#.


void PlayFab__Load_My_Top_Score()
{
	if (PlayFabClientAPI.IsClientLoggedIn() == false)
	{		
		return;
	}
	
			
	try
	{
		var leaderboard_name = "High Scores";
	
		var request = new GetPlayerStatisticsRequest() { StatisticNames = new List { leaderboard_name } };
		PlayFabClientAPI.GetPlayerStatistics(request, result =>
		{			
			foreach (var stat in result.Statistics)
			{
				//do something with each result
				Debug.Log(stat.Value);
			}
		},
		error =>
		{
			Debug.Log(error.GenerateErrorReport());
		});
	}
	catch (Exception ex)
	{
		Debug.LogError(ex);
	}
}