我有一个计时器在后台运行,并且在级别结束时我想显示排行榜。我想使用此计时器并将其转换为00:00格式00(分钟):00(秒)(即01:40)。那怎么可能?当关卡结束时,我只需要进行计算和转换。这就是我现在所拥有的。我正常启动计时器void Update(){ if(timerIsRunning) { mainGameTimer += Time.deltaTime; }}现在要以00:00格式添加计时器,我需要将其作为float传递,但在排行榜中将其作为字符串读取public void ShowResult(){ int min = Mathf.FloorToInt(mainGameTimer / 60); int sec = Mathf.FloorToInt(mainGameTimer % 60); users.Add(new User(userName, score , timeScore)); users.Sort(delegate (User us1, User us2) { return us2.GetScore().CompareTo(us1.GetScore()); }); int max = users.Count <= 10 ? users.Count : 10; for (int i = 0; i < max; i++) { //leaderListName[i].text = users[i].GetName() + "- " + users[i].GetScore() + "-" + Mathf.RoundToInt(users[i].GetTimeScore()) + "Sec"; leaderListName[i].text = users[i].GetName(); leaderListscore[i].text = users[i].GetScore().ToString(); leaderListtime[i].text = users[i].GetTimeScore().ToString(); }}class User{ string name; int score; float timeScore; public User(string _name, int _score , float _timeScore) { name = _name; score = _score; timeScore = _timeScore; } public string GetName() { return name; } public int GetScore() { return score; } public float GetTimeScore() { return timeScore; }}
2 回答
- 2 回答
- 0 关注
- 290 浏览
添加回答
举报
0/150
提交
取消