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.

148 lines
3.5 KiB

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using TMPro;
  6. using NaughtyAttributes;
  7. public class TextController : MonoBehaviour
  8. {
  9. [SerializeField]
  10. private TMP_Text m_levelText;
  11. [SerializeField]
  12. private TextMeshProUGUI m_detailsText;
  13. [SerializeField]
  14. private TextMeshProUGUI m_timerText;
  15. [SerializeField]
  16. private TextMeshProUGUI m_goText;
  17. [SerializeField]
  18. private Variables.Reference<bool> m_freezePlayer;
  19. [SerializeField]
  20. private Image m_backGround;
  21. [SerializeField, BoxGroup("Settings")]
  22. private float LevelFadeTime = 2;
  23. [SerializeField, BoxGroup("Settings")]
  24. private float Details1 = 1;
  25. [SerializeField, BoxGroup("Settings")]
  26. private float Details2 = 0.1f;
  27. [SerializeField, BoxGroup("Settings")]
  28. private float Details3 = 0.8f;
  29. [SerializeField, BoxGroup("Settings")]
  30. private float Fadetime = 1;
  31. [SerializeField, BoxGroup("Settings")]
  32. private float gotime = 0.5f;
  33. private IEnumerator Start()
  34. {
  35. m_backGround.gameObject.SetActive(true);
  36. m_freezePlayer.Value = true;
  37. yield return StartCoroutine(LevelName(LevelFadeTime));
  38. yield return StartCoroutine(DetailText(Details1, Details2, Details3));
  39. yield return StartCoroutine(Fade(Fadetime));
  40. yield return StartCoroutine(Go(gotime));
  41. }
  42. private IEnumerator LevelName(float time)
  43. {
  44. m_levelText.gameObject.SetActive(true);
  45. float start = 0;
  46. float end = 1;
  47. float elaspedTime = 0;
  48. Color color = m_levelText.color;
  49. while (elaspedTime < time)
  50. {
  51. float alpha = Mathf.Sin(Mathf.PI * (elaspedTime / time));
  52. color.a = alpha;
  53. m_levelText.color = color;
  54. yield return new WaitForEndOfFrame();
  55. elaspedTime += Time.deltaTime;
  56. }
  57. color.a = 0;
  58. m_levelText.color = color;
  59. m_levelText.gameObject.SetActive(false);
  60. }
  61. private IEnumerator DetailText(float time,float time2, float time3)
  62. {
  63. m_detailsText.gameObject.SetActive(true);
  64. m_detailsText.text = "10\n";
  65. yield return new WaitForSeconds(time);
  66. m_detailsText.text += "Seconds\n\n";
  67. yield return new WaitForSeconds(time);
  68. foreach(char c in "Get to the Chest")
  69. {
  70. m_detailsText.text += c;
  71. yield return new WaitForSeconds(time2);
  72. }
  73. yield return new WaitForSeconds(time3);
  74. }
  75. private IEnumerator Fade(float time)
  76. {
  77. float elaspedTime = 0;
  78. Color textColor = m_detailsText.color;
  79. Color backgroundColor = m_backGround.color;
  80. m_timerText.gameObject.SetActive(true);
  81. while (elaspedTime < time)
  82. {
  83. textColor.a = 1-(elaspedTime/time);
  84. backgroundColor.a = 1-(elaspedTime/time);
  85. m_backGround.color = backgroundColor;
  86. m_detailsText.color = textColor;
  87. yield return new WaitForEndOfFrame();
  88. elaspedTime+= Time.deltaTime;
  89. }
  90. textColor.a = 0;
  91. backgroundColor.a = 0;
  92. m_backGround.color = backgroundColor;
  93. m_detailsText.color = textColor;
  94. m_detailsText.gameObject.SetActive(false);
  95. m_backGround.gameObject.SetActive(false);
  96. }
  97. private IEnumerator Go(float time)
  98. {
  99. m_goText.gameObject.SetActive(true);
  100. yield return new WaitForSeconds(time);
  101. m_freezePlayer.Value = false;
  102. m_goText.gameObject.SetActive(false);
  103. }
  104. }