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

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using NaughtyAttributes;
using Variables;
public class TimerController : MonoBehaviour
{
[SerializeField,Header("References")]
private Reference<float> m_time;
[SerializeField]
private TextMeshProUGUI m_text;
[SerializeField, BoxGroup("Settings")]
private Color m_lowTimeColor = Color.red;
[SerializeField, BoxGroup("Settings")]
private Color m_defaultColor;
[SerializeField, BoxGroup("Settings")]
private float m_lowTimeAmount = 3;
private void Awake()
{
OnTimeChange(m_time.Value);
}
private void OnEnable()
{
m_time.OnValueChanged += OnTimeChange;
}
private void OnDisable()
{
m_time.OnValueChanged -= OnTimeChange;
}
private void OnTimeChange(float value)
{
m_text.text = value.ToString("0");
if (value <= m_lowTimeAmount)
{
m_text.color = m_lowTimeColor;
}
else
{
m_text.color = m_defaultColor;
}
}
}