2015-11-28 127 views
1

我使用函數Application.LoadLevelAsync(s);在我的比賽中,但它只停在89%。幫我。這是我的代碼:加載場景Unity

public void LoadScenes (string s) 
{ 
    if (!quit) { 
     SoundController.PlaySound (soundGame.ButtomClick); 
     progressBars.gameObject.SetActive (true); 
     background.SetActive (true); 
     text.gameObject.SetActive (true); 
     async = Application.LoadLevelAsync (s); 
     async.allowSceneActivation = false; 
     StartCoroutine (DisplayLoadingScreen()); 
    } 
} 
IEnumerator DisplayLoadingScreen() 
{ 
    while (!async.isDone) { 
     loadProgress = (int)(async.progress * 100); 
     text.text = "Loading Progress " + loadProgress + "%"; 
     progressBars.size = loadProgress; 
     yield return null; 
    } 
    if (async.isDone) { 
     Debug.Log ("Loading complete"); 
     async.allowSceneActivation = true; 
    } 
} 

回答

0

從我的經驗,AsyncOperation.progress可以在約89%的上限了,你已經發現。它可能看起來像是停留在這個消息上,當它真的需要加載的時間仍然很長時。即使完成時它也不會達到100%,所以如果你想實現一個加載條,那就沒用了。

因此,async.isDone可能永遠不會變成true

作爲一種變通方法,您可以設置async.allowSceneActivation = true;遲早,忽略async.progress乾脆:

async = Application.LoadLevelAsync (s); 
async.allowSceneActivation = true; 

我傾向於使用進度無關的旋轉加載圖標,而不是裝載吧,因爲這個問題。


在一個側面說明,我沒有測試過,others have said,這是一個編輯器,唯一的問題; async.progressasync.isDone實際上可能在獨立版本上工作。