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.

141 lines
2.6 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 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 Reference<bool> m_manuelDarknesscontrol;
  13. [SerializeField]
  14. private float m_time = 10;
  15. [SerializeField]
  16. private GameObject m_timerObject;
  17. [SerializeField]
  18. private TMPro.TextMeshProUGUI m_text;
  19. private bool m_hasTriggered = false;
  20. private void OnEnable()
  21. {
  22. m_lightLevel.OnValueChanged += OnLightChange;
  23. }
  24. private void OnDisable()
  25. {
  26. m_lightLevel.OnValueChanged -= OnLightChange;
  27. }
  28. private void Start()
  29. {
  30. m_text.gameObject.SetActive(false);
  31. }
  32. private void OnLightChange(float value)
  33. {
  34. if (!m_hasTriggered && !m_freezePlayer)
  35. {
  36. m_hasTriggered = true;
  37. StartCoroutine(Timer( m_time));
  38. }
  39. }
  40. private IEnumerator Timer(float time)
  41. {
  42. Debug.Log("Showing sneaky text");
  43. m_manuelDarknesscontrol.Value = true;
  44. float elapsedTime = 0;
  45. float fadeTime = 0.33f;
  46. m_text.gameObject.SetActive(true);
  47. Color color = m_text.color;
  48. while (elapsedTime< fadeTime)
  49. {
  50. m_lightLevel.Value = 1 - (elapsedTime / fadeTime);
  51. color.a = 1 - m_lightLevel;
  52. m_text.color = color;
  53. yield return new WaitForEndOfFrame();
  54. elapsedTime += Time.deltaTime;
  55. }
  56. m_lightLevel.Value = 0;
  57. color.a = 1 - m_lightLevel;
  58. m_text.color = color;
  59. m_timerObject.SetActive(false);
  60. Time.timeScale = 0.1f;
  61. elapsedTime = 0;
  62. fadeTime = 1.0f;
  63. while (elapsedTime < fadeTime)
  64. {
  65. Time.timeScale = 1 - (elapsedTime / fadeTime);
  66. yield return new WaitForEndOfFrame();
  67. elapsedTime += Time.unscaledDeltaTime;
  68. }
  69. yield return new WaitForSecondsRealtime(time);
  70. Time.timeScale = 1;
  71. m_timerObject.SetActive(true);
  72. elapsedTime = 0;
  73. fadeTime = 0.25f;
  74. while (elapsedTime < fadeTime)
  75. {
  76. m_lightLevel.Value = (elapsedTime / fadeTime);
  77. color.a = 1 - (elapsedTime / fadeTime);
  78. m_text.color = color;
  79. yield return new WaitForEndOfFrame();
  80. elapsedTime += Time.deltaTime;
  81. }
  82. m_text.gameObject.SetActive(false);
  83. m_manuelDarknesscontrol.Value = false;
  84. }
  85. }