BattleClockUI.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using System.Collections;
  4. public class BattleClockUI : MonoBehaviour {
  5. public Sprite[] countDownSpriteArr;
  6. public Image countDownImg;
  7. private int currentCountDown = 100;
  8. public Animator animator;
  9. private BattleController battleController;
  10. public void Init(BattleController battleController)
  11. {
  12. this.battleController = battleController;
  13. FixedUpdate();
  14. }
  15. // Update is called once per frame
  16. public void UpdateFreeClock (float time)
  17. {
  18. if(time <= 10)
  19. {
  20. int countDown = (int)Mathf.Ceil(time);
  21. if(currentCountDown != countDown)
  22. {
  23. currentCountDown = countDown;
  24. int index = Mathf.Max(currentCountDown-1, 0);
  25. countDownImg.sprite = countDownSpriteArr[index];
  26. if(countDown == 1)
  27. animator.Play("CountDownFinal", 0, 0);
  28. else
  29. animator.Play("CountDown", 0, 0);
  30. }
  31. }
  32. }
  33. void FixedUpdate ()
  34. {
  35. if(battleController == null)
  36. return;
  37. float battleFreeTimeLeft = battleController.clock.freeTimeLeft;
  38. if(battleFreeTimeLeft == 0 && battleController.clock.timeLeft != 0)
  39. {
  40. if(animator.GetCurrentAnimatorStateInfo(0).normalizedTime >= 1f)
  41. gameObject.SetActive(false);
  42. //UpdateClock(battleController.clock.timeLeft);
  43. }
  44. else
  45. {
  46. UpdateFreeClock(battleFreeTimeLeft);
  47. }
  48. }
  49. }