| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class HunterGameView : MonoBehaviour
- {
- Text t1;
- Text t2;
- Text t3;
- ChallengeGameMode gameMode;
- void Start()
- {
- t1 = this.transform.Find("T1").GetComponent<Text>();
- t2 = this.transform.Find("T2").GetComponent<Text>();
- t3 = this.transform.Find("T3").GetComponent<Text>();
- gameMode = (ChallengeGameMode) GameMgr.ins.gameMode;
- }
-
- void FixedUpdate()
- {
- RenderAnimalCount();
- RenderArrowCount();
- RenderTime();
- if (GameMgr.ins.gameOver) {
- Destroy(this.gameObject);
- }
- }
- string[] animalNames = {"野兔", "野鸡", "野狼"};
- void RenderAnimalCount() {
- string animalName = animalNames[gameMode.animalTypeID];
- t1.text = $"剩余{animalName}:{gameMode.animalCount}";
- }
- void RenderArrowCount() {
- t2.text = $"剩余箭矢:{gameMode.arrowCount}";
- }
- int lastRenderTime = -1;
- void RenderTime() {
- int curTime = Mathf.CeilToInt(gameMode.time);
- if (curTime != lastRenderTime) {
- lastRenderTime = curTime;
- t3.text = GetTimeStr(curTime);
- }
- }
- string GetTimeStr(int second) {
- string str = "";
- int m = second / 60;
- if (m < 10) {
- str += 0;
- }
- str += m;
- str += " : ";
- int s = second % 60;
- if (s < 10)
- {
- str += 0;
- }
- str += s;
- return str;
- }
- }
|