leaderboard added on terminal/console
This commit is contained in:
26
Assets/LeaderBoardUI.cs
Normal file
26
Assets/LeaderBoardUI.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System.Text;
|
||||
using TMPro;
|
||||
using Unity.Services.Leaderboards;
|
||||
using UnityEngine;
|
||||
|
||||
public class LeaderBoardUI : MonoBehaviour
|
||||
{
|
||||
public TextMeshProUGUI scoretext;
|
||||
private const string leaderBoardID = "helix_leaderboard";
|
||||
|
||||
public async void LoadLeaderBoard()
|
||||
{
|
||||
var score = await LeaderboardsService.Instance.GetScoresAsync(leaderBoardID, new GetScoresOptions { Limit = 10 });
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
int rank = 1;
|
||||
|
||||
foreach (var scoreEntry in score.Results)
|
||||
{
|
||||
sb.AppendLine($"{rank}.{scoreEntry.PlayerName}- Score: {scoreEntry.Score}");
|
||||
rank++;
|
||||
}
|
||||
|
||||
scoretext.text = sb.ToString();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user