public class LevelLoader : MonoBehaviour {
public GameObject loadingPanle;
public Slider slider;
public Text progressText;
public void LoadLevel(int levelIndex)
{
StartCoroutine(LoadAsynchronously(levelIndex));
}
IEnumerator LoadAsynchronously(int sceneIndex)
{
AsyncOperation operation = SceneManager.LoadSceneAsync(sceneIndex);
loadingPanle.SetActive(true);
while (!operation.isDone)
{
float progress = Mathf.Clamp01(operation.progress / .9f);
slider.value = progress;
progressText.text = progress * 100 + "%";
yield return null;
}
}
}