| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- 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 List<GameObject> tooltips = new List<GameObject>();
- public PauseMenu pauseMenu;
- // 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 += 0.05f*Time.deltaTime;
- if (loadingSlider.value >= 1)
- {
- 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);
- }
- }
|