using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using System.Collections;
public class GotoSceneForAsyncOperation : MonoBehaviour
{
public GameObject loadScene;
public Slider loadSlider;
public Text showText;
public void LoadNextScene()
{
StartCoroutine(Loadlevel());
}
IEnumerator Loadlevel()
{
loadScene.SetActive(true);
AsyncOperation operation = SceneManager.LoadSceneAsync(SceneManager.GetActiveScene().buildIndex + 1);
operation.allowSceneActivation = false;
while (!operation.isDone)
{
loadSlider.value = operation.progress;
showText.text = operation.progress * 100 + "%";
if (operation.progress >= 0.9f)
{
loadSlider.value = 1;
showText.text = "Pls enter any keys~";
if (Input.anyKeyDown)
{
operation.allowSceneActivation = true;
}
}
yield return null;
}
}
}
|