LoadingScreen.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System.Collections;
  2. using System.Runtime.CompilerServices;
  3. using TMPro;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. public class LoadingScreen : MonoBehaviour
  7. {
  8. [SerializeField] GameObject loadingScreen;
  9. [SerializeField] TextMeshProUGUI wiseQuote;
  10. private bool bIsUILogicSet = false;
  11. [SerializeField] Slider progressBar;
  12. [SerializeField] GameObject startPlayingButton;
  13. [SerializeField] string[] wiseQuotes;
  14. private bool bIsTimerOver = false;
  15. private void Awake()
  16. {
  17. //loadingScreen = GameObject.Find("LoadingScreen");
  18. if (startPlayingButton)
  19. {
  20. startPlayingButton.SetActive(false);
  21. }
  22. if (loadingScreen)
  23. {
  24. loadingScreen.SetActive(true);
  25. }
  26. StartCoroutine(StartTimer(5f));
  27. wiseQuote.text = wiseQuotes[Random.Range(0, wiseQuotes.Length)];
  28. }
  29. IEnumerator StartTimer(float duration)
  30. {
  31. float timer = 0f;
  32. progressBar.maxValue = duration;
  33. while(timer < duration)
  34. {
  35. timer += Time.deltaTime;
  36. progressBar.value = timer;
  37. yield return null;
  38. }
  39. progressBar.value = duration;
  40. bIsTimerOver = true;
  41. }
  42. private void Update()
  43. {
  44. if (GameManager.gameManagerInstance.bHasPlayerLanded && !bIsUILogicSet && bIsTimerOver)
  45. {
  46. startPlayingButton.SetActive(true);
  47. bIsUILogicSet = true;
  48. }
  49. }
  50. public void OnStartButtonClick()
  51. {
  52. loadingScreen.SetActive(false);
  53. GameManager.gameManagerInstance.bIsGameStarted = true;
  54. }
  55. }