LoadingScreen.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 List<GameObject> tooltips = new List<GameObject>();
  11. public PauseMenu pauseMenu;
  12. // Start is called once before the first execution of Update after the MonoBehaviour is created
  13. void Start()
  14. {
  15. pauseMenu.SetIsLoading(true);
  16. loadingSlider = LoadingScreenUI.GetComponentInChildren<Slider>();
  17. loadingSlider.value = 0f;
  18. }
  19. // Update is called once per frame
  20. void Update()
  21. {
  22. loadingSlider.value += 0.05f*Time.deltaTime;
  23. if (loadingSlider.value >= 1)
  24. {
  25. pauseMenu.SetIsLoading(false);
  26. LoadingScreenUI.SetActive(false);
  27. }
  28. }
  29. public void OnEnable()
  30. {
  31. ShowRandomTooltip();
  32. }
  33. void ShowRandomTooltip()
  34. {
  35. if (tooltips.Count == 0)
  36. return;
  37. // Disable all tooltips first
  38. foreach (GameObject tooltip in tooltips)
  39. {
  40. tooltip.SetActive(false);
  41. }
  42. // Pick and enable one random tooltip
  43. int randomIndex = Random.Range(0, tooltips.Count);
  44. tooltips[randomIndex].SetActive(true);
  45. }
  46. }