using UnityEngine; using UnityEngine.UI; using System.Collections; public class BattleClockUI : MonoBehaviour { public Sprite[] countDownSpriteArr; public Image countDownImg; private int currentCountDown = 100; public Animator animator; private BattleController battleController; public void Init(BattleController battleController) { this.battleController = battleController; FixedUpdate(); } // Update is called once per frame public void UpdateFreeClock (float time) { if(time <= 10) { int countDown = (int)Mathf.Ceil(time); if(currentCountDown != countDown) { currentCountDown = countDown; int index = Mathf.Max(currentCountDown-1, 0); countDownImg.sprite = countDownSpriteArr[index]; if(countDown == 1) animator.Play("CountDownFinal", 0, 0); else animator.Play("CountDown", 0, 0); } } } void FixedUpdate () { if(battleController == null) return; float battleFreeTimeLeft = battleController.clock.freeTimeLeft; if(battleFreeTimeLeft == 0 && battleController.clock.timeLeft != 0) { if(animator.GetCurrentAnimatorStateInfo(0).normalizedTime >= 1f) gameObject.SetActive(false); //UpdateClock(battleController.clock.timeLeft); } else { UpdateFreeClock(battleFreeTimeLeft); } } }