在遊戲中,常常能夠看到從一個關卡跳到另外一個關卡時,有一個顯眼的進度條,研究了下,其時也很簡單:ide
public void LoadAScene()
{
StartCoroutine(LoadSceneAsync("SampleScene"));
}遊戲
IEnumerator LoadSceneAsync(string sceneName)
{
AsyncOperation operation = SceneManager.LoadSceneAsync(sceneName);
operation.allowSceneActivation = false;
while (!operation.isDone)
{
#if UNITY_EDITOR
Debug.Log("Progress is :" + operation.progress);
#endif
float progress = Mathf.Clamp01(operation.progress / 0.9f);
ProgressSlider.value = progress;
ProgressText.text = ((int)progress * 100).ToString() + "%";
yield return null;
}
operation.allowSceneActivation = true;string
}io