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.

142 lines
2.7 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. Debug.Log("Here");
  35. if (!m_hasTriggered && !m_freezePlayer)
  36. {
  37. m_hasTriggered = true;
  38. StartCoroutine(Timer( m_time));
  39. }
  40. }
  41. private IEnumerator Timer(float time)
  42. {
  43. Debug.Log("Showing sneaky text");
  44. m_manuelDarknesscontrol.Value = true;
  45. float elapsedTime = 0;
  46. float fadeTime = 0.33f;
  47. m_text.gameObject.SetActive(true);
  48. Color color = m_text.color;
  49. while (elapsedTime< fadeTime)
  50. {
  51. m_lightLevel.Value = 1 - (elapsedTime / fadeTime);
  52. color.a = 1 - m_lightLevel;
  53. m_text.color = color;
  54. yield return new WaitForEndOfFrame();
  55. elapsedTime += Time.deltaTime;
  56. }
  57. m_lightLevel.Value = 0;
  58. color.a = 1 - m_lightLevel;
  59. m_text.color = color;
  60. m_timerObject.SetActive(false);
  61. Time.timeScale = 0.1f;
  62. elapsedTime = 0;
  63. fadeTime = 1.0f;
  64. while (elapsedTime < fadeTime)
  65. {
  66. Time.timeScale = 1 - (elapsedTime / fadeTime);
  67. yield return new WaitForEndOfFrame();
  68. elapsedTime += Time.unscaledDeltaTime;
  69. }
  70. yield return new WaitForSecondsRealtime(time);
  71. Time.timeScale = 1;
  72. m_timerObject.SetActive(true);
  73. elapsedTime = 0;
  74. fadeTime = 0.25f;
  75. while (elapsedTime < fadeTime)
  76. {
  77. m_lightLevel.Value = (elapsedTime / fadeTime);
  78. color.a = 1 - (elapsedTime / fadeTime);
  79. m_text.color = color;
  80. yield return new WaitForEndOfFrame();
  81. elapsedTime += Time.deltaTime;
  82. }
  83. m_text.gameObject.SetActive(false);
  84. m_manuelDarknesscontrol.Value = false;
  85. }
  86. }