HunterGameView.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class HunterGameView : MonoBehaviour
  6. {
  7. Text t1;
  8. Text t2;
  9. Text t3;
  10. ChallengeGameMode gameMode;
  11. void Start()
  12. {
  13. t1 = this.transform.Find("T1").GetComponent<Text>();
  14. t2 = this.transform.Find("T2").GetComponent<Text>();
  15. t3 = this.transform.Find("T3").GetComponent<Text>();
  16. gameMode = (ChallengeGameMode) GameMgr.ins.gameMode;
  17. }
  18. void FixedUpdate()
  19. {
  20. RenderAnimalCount();
  21. RenderArrowCount();
  22. RenderTime();
  23. if (GameMgr.ins.gameOver) {
  24. Destroy(this.gameObject);
  25. }
  26. }
  27. string[] animalNames = {"野兔", "野鸡", "野狼"};
  28. void RenderAnimalCount() {
  29. string animalName = animalNames[gameMode.animalTypeID];
  30. t1.text = $"剩余{animalName}:{gameMode.animalCount}";
  31. }
  32. void RenderArrowCount() {
  33. t2.text = $"剩余箭矢:{gameMode.arrowCount}";
  34. }
  35. int lastRenderTime = -1;
  36. void RenderTime() {
  37. int curTime = Mathf.CeilToInt(gameMode.time);
  38. if (curTime != lastRenderTime) {
  39. lastRenderTime = curTime;
  40. t3.text = GetTimeStr(curTime);
  41. }
  42. }
  43. string GetTimeStr(int second) {
  44. string str = "";
  45. int m = second / 60;
  46. if (m < 10) {
  47. str += 0;
  48. }
  49. str += m;
  50. str += " : ";
  51. int s = second % 60;
  52. if (s < 10)
  53. {
  54. str += 0;
  55. }
  56. str += s;
  57. return str;
  58. }
  59. }