我有这样的收藏
我正在尝试获取排行榜的名称和分数,但名字缺少分数,如下所示
这是我的代码:
public void GetLeaderboardData()
{
Firebase.Firestore.Query allUsersQuery = db.Collection("users").OrderByDescending("timestamp").Limit(20);
allUsersQuery.GetSnapshotAsync().ContinueWithOnMainThread(task => {
QuerySnapshot allUsersQuerySnapshot = task.Result;
foreach (DocumentSnapshot documentSnapshot in allUsersQuerySnapshot.Documents)
{
//Debug.Log (String.Format ("Document data for {0} document:", documentSnapshot.Id));
Dictionary<string, object> user = documentSnapshot.ToDictionary();
foreach (KeyValuePair<string, object> pair in user)
{
Debug.Log(String.Format("{0}: {1}", pair.Key, pair.Value));
if (pair.Key == "score")
{
score = (string)pair.Value;
}
if (pair.Key == "name")
{
uname = (string)pair.Value;
GameObject tBar = Instantiate(postPrefab.gameObject, transform.position, transform.rotation);
tBar.transform.SetParent(PostParent, false);
tBar.transform.GetChild(0).GetComponent<Text>().text = score;
tBar.transform.GetChild(2).GetComponent<Text>().text = uname;
tBar.gameObject.name = documentSnapshot.Id;
}
}
}
});
}
我做错了什么?任何人都可以帮忙吗?