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.

62 lines
1.2 KiB

2 years ago
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Variables;
  5. public class SneakyTextController : MonoBehaviour
  6. {
  7. [SerializeField]
  8. private Reference<float> m_lightLevel;
  9. [SerializeField]
  10. private Reference<bool> m_freezePlayer;
  11. [SerializeField]
  12. private float m_time = 10;
  13. [SerializeField]
  14. private TMPro.TextMeshProUGUI m_text;
  15. private bool m_hasTriggered = false;
  16. private void OnEnable()
  17. {
  18. m_lightLevel.OnValueChanged += OnLightChange;
  19. }
  20. private void OnDisable()
  21. {
  22. m_lightLevel.OnValueChanged -= OnLightChange;
  23. }
  24. private void Start()
  25. {
  26. m_text.gameObject.SetActive(false);
  27. }
  28. private void OnLightChange(float value)
  29. {
  30. Color color = m_text.color;
  31. color.a = 1 - m_lightLevel;
  32. m_text.color = color;
  33. if (!m_hasTriggered && !m_freezePlayer)
  34. {
  35. m_hasTriggered = true;
  36. StartCoroutine(Timer( m_time));
  37. }
  38. }
  39. private IEnumerator Timer(float time)
  40. {
  41. Debug.Log("here");
  42. m_text.gameObject.SetActive(true);
  43. yield return new WaitForSeconds(time);
  44. m_text.gameObject.SetActive(false);
  45. }
  46. }