-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathleaderboardEntryUI.cs
More file actions
36 lines (30 loc) · 958 Bytes
/
leaderboardEntryUI.cs
File metadata and controls
36 lines (30 loc) · 958 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using UnityEngine;
using TMPro;
public class LeaderboardEntryUI : MonoBehaviour
{
[SerializeField] private TextMeshProUGUI rankText;
[SerializeField] private TextMeshProUGUI usernameText;
[SerializeField] private TextMeshProUGUI timeText;
public void SetEntryData(int rank, string username, float completionTime)
{
if (rankText != null)
{
rankText.text = rank.ToString();
}
if (usernameText != null)
{
usernameText.text = username;
}
if (timeText != null)
{
timeText.text = FormatTime(completionTime);
}
}
private string FormatTime(float timeInSeconds)
{
int minutes = (int)(timeInSeconds / 60);
int seconds = (int)(timeInSeconds % 60);
int milliseconds = (int)((timeInSeconds * 1000) % 1000);
return string.Format("{0:00}:{1:00}.{2:000}", minutes, seconds, milliseconds);
}
}