loading screen unity

Code Example - loading screen unity

                
                        using System.Collections;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using TMPro;

public class LoadingScreen : MonoBehaviour
{
	[HideInInspector]
	private TextMeshProUGUI loadingText;
	[HideInInspector]
	private Slider loadingSlider;

	public void LoadScene(int sceneNumber)
	{
		StartCoroutine(LoadSceneAsync(sceneNumber));
	}

	IEnumerator LoadSceneAsync(int sceneIndex)
	{
		AsyncOperation operation = SceneManager.LoadSceneAsync(sceneIndex);

		while (!operation.isDone)
		{
			Debug.Log("Operation progress");

			float progress = Mathf.Clamp01(operation.progress / 0.9f);

			loadingText.text = Mathf.RoundToInt(progress * 100) + "%";
			loadingSlider.value = progress;

			yield return new WaitForEndOfFrame();
		}
	}
}