added leaderboard
This commit is contained in:
1 parent
51b5659f4a
commit
8a9fe611e0
9 files changed
+1606
-25
No files matched your search
@@ -0,0 +1,43 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using Code.Saves;
|
||||
using System.Text;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace Code.UI
|
||||
{
|
||||
public class LeaderboardController : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private TMP_Text leaderboardText;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
DisplayLeaderboard();
|
||||
}
|
||||
|
||||
private void DisplayLeaderboard()
|
||||
{
|
||||
var data = SaveManager.Load();
|
||||
|
||||
if (data.leaderboard == null || data.leaderboard.Count == 0)
|
||||
{
|
||||
leaderboardText.text = "No records yet!";
|
||||
return;
|
||||
}
|
||||
|
||||
var sb = new StringBuilder();
|
||||
for (var i = 0; i < data.leaderboard.Count; i++)
|
||||
{
|
||||
var entry = data.leaderboard[i];
|
||||
sb.AppendLine($"{i + 1}. {entry.playerName} - {entry.score} coins");
|
||||
}
|
||||
|
||||
leaderboardText.text = sb.ToString();
|
||||
}
|
||||
|
||||
public void LoadMenu()
|
||||
{
|
||||
SceneManager.LoadScene("MainMenu");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user