12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- using UnityEngine;
- using System.Collections;
- using TMPro;
- public class TimerEffects : MonoBehaviour
- {
- TextMeshProUGUI label;
- int lastPanicNumber;
- void Awake()
- {
- label = GetComponentInChildren<TextMeshProUGUI>();
- label.text = "";
- NotificationCenter.AddListener(OnGameStart, NotificationType.GameStart);
- NotificationCenter.AddListener(OnGameOver, NotificationType.GameOver);
- NotificationCenter.AddListener(OnTimeLeftUpdate, NotificationType.TimeLeftUpdate);
- }
- private void OnGameOver(Notification note)
- {
- //throw new System.NotImplementedException();
- }
- void OnDestroy()
- {
- NotificationCenter.RemoveListener(OnGameOver, NotificationType.GameOver);
- NotificationCenter.RemoveListener(OnGameStart, NotificationType.GameStart);
- NotificationCenter.RemoveListener(OnTimeLeftUpdate, NotificationType.TimeLeftUpdate);
- }
- void OnGameStart(Notification note)
- {
- label.text = "";
- }
- void OnTimeLeftUpdate(Notification note)
- {
- int timeLeft = (int)((float)note.data);
- label.text = timeLeft.ToString();
- if (timeLeft <= 10 && lastPanicNumber != timeLeft)
- {
- lastPanicNumber = timeLeft;
- Panic();
- }
- }
- public void Reset()
- {
- iTween.Stop(gameObject);
- transform.localScale = Vector3.one;
- label.color = Color.white;
- //label.MarkAsChangedLite();
- }
- void Panic()
- {
- SoundManager.Play(SoundEvent.countDownTick);
- iTween.Stop(gameObject);
- transform.localScale = Vector3.one * 3;
- iTween.ScaleTo(gameObject, iTween.Hash(
- "scale", Vector3.one,
- "time", 0.5f));
- iTween.ValueTo(gameObject, iTween.Hash(
- "from", 0,
- "to", 1,
- "time", 0.75f,
- "onupdate", "OniTweenUpdate",
- "onupdatetarget", gameObject));
- }
- void OniTweenUpdate(float newValue)
- {
- label.color = new Color(1, newValue, newValue);
- //label.MarkAsChangedLite();
- }
- }
|