| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- using System;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using Random = UnityEngine.Random;
- public class LoadingScreen : MonoBehaviour
- {
- public GameObject LoadingScreenUI;
- private Slider loadingSlider;
- public GameObject clickToContinue;
- public List<GameObject> tooltips = new List<GameObject>();
- public PauseMenu pauseMenu;
- public float loadingAdded = 0.5f;
- // Start is called once before the first execution of Update after the MonoBehaviour is created
- void Start()
- {
- pauseMenu.SetIsLoading(true);
- loadingSlider = LoadingScreenUI.GetComponentInChildren<Slider>();
- loadingSlider.value = 0f;
- }
- // Update is called once per frame
- void Update()
- {
- loadingSlider.value += loadingAdded * Time.deltaTime;
- if (loadingSlider.value >= 1)
- {
- clickToContinue.SetActive(true);
- if (Input.anyKeyDown)
- {
- pauseMenu.SetIsLoading(false);
- LoadingScreenUI.SetActive(false);
- }
-
- }
- }
- public void OnEnable()
- {
- ShowRandomTooltip();
- }
- void ShowRandomTooltip()
- {
- if (tooltips.Count == 0)
- return;
- // Disable all tooltips first
- foreach (GameObject tooltip in tooltips)
- {
- tooltip.SetActive(false);
- }
- // Pick and enable one random tooltip
- int randomIndex = Random.Range(0, tooltips.Count);
- tooltips[randomIndex].SetActive(true);
- }
- }
|