using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine.SceneManagement; using TMPro; using UnityEngine; public class LoadScene : MonoBehaviour { public TextMeshProUGUI lbl; // Start is called before the first frame update void Start() { StartCoroutine(CorouLoadScene("LoadScene2")); } // Update is called once per frame void Update() { } private IEnumerator CorouLoadScene(string sceneName) { int displayProgress = 0; int toProgress = 0; AsyncOperation op = SceneManager.LoadSceneAsync(sceneName); op.allowSceneActivation = false; while(op.progress < 0.9f){ toProgress = (int)op.progress * 100; while(displayProgress < toProgress) { ++displayProgress; setLoadingPercentage(displayProgress); yield return new WaitForEndOfFrame(); } } toProgress = 100; while(displayProgress < toProgress) { ++displayProgress; setLoadingPercentage(displayProgress); yield return new WaitForEndOfFrame(); } op.allowSceneActivation = true; } private void setLoadingPercentage(int progress) { lbl.text = progress.ToString(); } }