using UnityEngine; namespace UI { public class LoadingScreenUIController : MonoBehaviour { public GameObject loadingScreen; public float displayStartTime; // min time to show the loading screen (in seconds) [SerializeField] private float minTimeToShow = 2.0f; public static LoadingScreenUIController Instance { get; private set; } private void Awake() { if (Instance == null) { Instance = this; DontDestroyOnLoad(gameObject); } else { Destroy(gameObject); } if (loadingScreen == null) // assign this to the loading screen loadingScreen = gameObject; } // check if the loading screen should be displayed private void Update() { if (Time.time - displayStartTime > minTimeToShow) HideLoadingScreen(); } // display the loading screen public void ShowLoadingScreen() { loadingScreen.SetActive(true); } // hide the loading screen public void HideLoadingScreen() { loadingScreen.SetActive(false); } // trigger the loading screen public void TriggerLoadingScreen() { displayStartTime = Time.time; ShowLoadingScreen(); } } }