Global Game Jam 2022
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.1 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using TMPro;
  5. using NaughtyAttributes;
  6. using Variables;
  7. public class TimerController : MonoBehaviour
  8. {
  9. [SerializeField,Header("References")]
  10. private Reference<float> m_time;
  11. [SerializeField]
  12. private TextMeshProUGUI m_text;
  13. [SerializeField, BoxGroup("Settings")]
  14. private Color m_lowTimeColor = Color.red;
  15. [SerializeField, BoxGroup("Settings")]
  16. private Color m_defaultColor;
  17. [SerializeField, BoxGroup("Settings")]
  18. private float m_lowTimeAmount = 3;
  19. private void Awake()
  20. {
  21. OnTimeChange(m_time.Value);
  22. }
  23. private void OnEnable()
  24. {
  25. m_time.OnValueChanged += OnTimeChange;
  26. }
  27. private void OnDisable()
  28. {
  29. m_time.OnValueChanged -= OnTimeChange;
  30. }
  31. private void OnTimeChange(float value)
  32. {
  33. m_text.text = value.ToString("0");
  34. if (value <= m_lowTimeAmount)
  35. {
  36. m_text.color = m_lowTimeColor;
  37. }
  38. else
  39. {
  40. m_text.color = m_defaultColor;
  41. }
  42. }
  43. }