LoadingScreen.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using Random = UnityEngine.Random;
  6. public class LoadingScreen : MonoBehaviour
  7. {
  8. public GameObject LoadingScreenUI;
  9. private Slider loadingSlider;
  10. public GameObject clickToContinue;
  11. public List<GameObject> tooltips = new List<GameObject>();
  12. public PauseMenu pauseMenu;
  13. public float loadingAdded = 0.5f;
  14. // Start is called once before the first execution of Update after the MonoBehaviour is created
  15. void Start()
  16. {
  17. pauseMenu.SetIsLoading(true);
  18. loadingSlider = LoadingScreenUI.GetComponentInChildren<Slider>();
  19. loadingSlider.value = 0f;
  20. }
  21. // Update is called once per frame
  22. void Update()
  23. {
  24. loadingSlider.value += loadingAdded * Time.deltaTime;
  25. if (loadingSlider.value >= 1)
  26. {
  27. clickToContinue.SetActive(true);
  28. if (Input.anyKeyDown)
  29. {
  30. pauseMenu.SetIsLoading(false);
  31. LoadingScreenUI.SetActive(false);
  32. }
  33. }
  34. }
  35. public void OnEnable()
  36. {
  37. ShowRandomTooltip();
  38. }
  39. void ShowRandomTooltip()
  40. {
  41. if (tooltips.Count == 0)
  42. return;
  43. // Disable all tooltips first
  44. foreach (GameObject tooltip in tooltips)
  45. {
  46. tooltip.SetActive(false);
  47. }
  48. // Pick and enable one random tooltip
  49. int randomIndex = Random.Range(0, tooltips.Count);
  50. tooltips[randomIndex].SetActive(true);
  51. }
  52. }