I have a mini-game with a leaderboard using firebase database realtime.
After I got list of user-score from firebase, I would like to get the score of the current user who was out of the list.
It's easy to get the score of the current user but how to know the rank in list which was OrderByChild("score").
This is the code to get the leaderboard.
List<UserScore> leaderBoard = new List<UserScore>();
FirebaseDatabase.DefaultInstance
.GetReference("user-scores")
.OrderByChild("score")
.LimitToLast(10)
.GetValueAsync()
.ContinueWith(task =>
{
if (task.IsFaulted)
{
Debug.Log("Fail To Load");
}
else if (task.IsCompleted)
{
DataSnapshot snapshot = task.Result;
foreach (DataSnapshot h in snapshot.Children)
{
UserScore userScore = new UserScore(h.Child("uid").Value.ToString(), h.Child("name").Value.ToString(), h.Child("photo").Value.ToString(),int.Parse(h.Child("score").Value.ToString()));
leaderBoard.Add(userScore);
}
}
});