- Home /
LoadLevelAsync Wait to load (C#)
Hello, I'm trying to load a level using a loading screen and so far I've got a bit of it working. However I'd like the user to have to press a key before continuing to the actual level. This is what I have so far and in my mind it should work, but obviously its not :/
IEnumerator LoadLevel()
{
AsyncOperation async = Application.LoadLevelAsync(levelName);
while(!async.isDone)//This hits 90% and then loads level automatically
{
percent.text = (async.progress * 100).ToString("F0") + "%";
yield return new WaitForEndOfFrame();
}
while(async.isDone)//This isn't working
{
percent.text = "Press Any Key to Continue";
if(Input.anyKeyDown)
yield return async;
}
}
ok I've discovered AsyncOperation.allowSceneActivation, and set that to false. But the issue I'm having now is that while(async.isdone) is never triggering.
Bump! I'm having the exact same problem! As far as I can tell it's a fundamental bug with Unity itself. Has anyone else experienced this?
I discovered through some research that it stops at .9f (magic number). So just check for that in your code.
90% is the maximum it can load in the background iirc, the rest involves actual scene manipulation. You can check for when the load is near 0.9f and then finish after that.
Answer by $$anonymous$$ · Mar 21, 2019 at 12:49 PM
https://docs.unity3d.com/ja/current/ScriptReference/AsyncOperation-allowSceneActivation.html The answer is here. Shortly, async.progress always keeps <= 0.9f so async.isDone is always FALSE.
Your answer
Follow this Question
Related Questions
how do I load a 3d model on the fly 0 Answers
How do you run a exe from code 1 Answer
Can't open file when loading from WWW stream 2 Answers
Share creations with friends 0 Answers
How to Save and Load a list of Scriptable Objects from a File? 2 Answers