using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class HunterGameView : MonoBehaviour { Text t1; Text t2; Text t3; ChallengeGameMode gameMode; WolfHuntGameMode gameMode1; void Start() { t1 = this.transform.Find("T1").GetComponent(); t2 = this.transform.Find("T2").GetComponent(); t3 = this.transform.Find("T3").GetComponent(); gameMode = (ChallengeGameMode) GameMgr.ins.gameMode; if (GameMgr.gameType == 5) { gameMode1 = (WolfHuntGameMode) gameMode; t2.gameObject.SetActive(false); t3.gameObject.SetActive(false); } else { hpUI.SetActive(false); } } void FixedUpdate() { RenderAnimalCount(); if (GameMgr.gameType == 5) { RenderHP(); } else { 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; } [SerializeField] GameObject hpUI; [SerializeField] Image hpBar; [SerializeField] Text hpText; void RenderHP() { hpBar.fillAmount = Mathf.Lerp(hpBar.fillAmount, (float) gameMode1.hp / gameMode1.hpMax, Time.deltaTime * 6); hpText.text = $"{gameMode1.hp}/{gameMode1.hpMax}"; } }