I'm trying to make a loading scene with a progress bar using *LoadLevelAsync()*. I've gone through every single post I could find and none of them are helpful.
The basic problem I've encountered: every single piece of code, including the unity documentation, uses something like this: "*yield return level.isDone;*". However, I've found that this pauses the game until the level has been loaded, essentially turning *LoadLevelAsync()* into *LoadLevel()*. Since what I want is for the game to, you know, actually do something while it's loading (Otherwise I'd use *LoadLevel()*), this turns most of the code out there useless. This happens in the editor and when built.
I must say I don't really have any experience with CoRoutines and Multithreading, so most of what I've tried was guesswork. From what I've read, I need to have a yield somewhere in the function. I haven't been able to use it in any of the other ways shown in the 5 year+ questions that are somehow on the front page of my google searches (such as having "*yield;*" at the end of the loop).
Please, could someone tell me how to use *LoadLevelAsync()* in the **only way it makes sense** (not pausing the game), and using code that works with Unity 5, and not Unity 3?
**My code:**
public Text mapName;
public Text loadingStatus;
void Start(){
StartCoroutine(LoadAsync("Map1"));
}
private IEnumerator LoadAsync(string levelName){
AsyncOperation level = Application.LoadLevelAsync(levelName);
mapName.text = "Loading" + levelName + "...";
while(!level.isDone){
loadingStatus.text = Mathf.RoundToInt(level.progress*10)/10 + "%";
yield return level.isDone;
}
}
(ᴵ'ᵐ ᵍᵒⁱⁿᵍ ᵐᵃᵈ, ˢᵉⁿᵈ ʰᵉˡᵖ)
↧