| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class GameCanvas : MonoBehaviour
- {
- public Text timeText;
- public static GameCanvas ins;
- void Start()
- {
- ins = this;
- }
- void Update()
- {
- RefreshRender();
- }
- void RefreshRender()
- {
- RenderTime(GameController.ins.time);
- RenderScore(0, GameController.ins.scores[0]);
- RenderScore(1, GameController.ins.scores[1]);
- }
- void RenderTime(float time)
- {
- timeText.text = GetTimeStr(time);
- }
- void RenderScore(int playerIndex, float score)
- {
- transform.Find("ScoreBG" + (playerIndex + 1)).GetComponentInChildren<Text>().text =
- "玩家得分" + (float)System.Math.Round(score, CommonConfig.ringsPrecision);
- }
- string GetTimeStr(float time)
- {
- int seconds = (int)Mathf.Ceil(time);
- string str = "";
- int m = seconds / 60;
- if (m < 10)
- {
- str += 0;
- }
- str += m;
- str += " : ";
- int s = seconds % 60;
- if (s < 10)
- {
- str += 0;
- }
- str += s;
- return str;
- }
- }
|