- Home /
Question by
juanmanolo · Jul 24, 2019 at 09:57 AM ·
coroutinetimescaleload sceneasync
Loading screen with async load and freezing gameplay
Hi, I'm trying to make a load screen that uses async load.
For that I'm using a coroutine, and it works fine. But I want that if the load time is too small let the "load screen" to last a minimum time, I mean I don't want a instantaneus "loading" and "press a key to continue" thing.
For that I use a first "yield return new WaitForSeconds(3f)" and then I check for the async load. This is the code:
IEnumerator Example()
{
// An object with red color to indicate is loading.
gameObject.GetComponent<Renderer>().material.color = Color.red;
AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(nextScene);
asyncLoad.allowSceneActivation = false;
// wait a minimum time in this "loading screen".
yield return new WaitForSeconds(3f);
print(Time.time);
while(!asyncLoad.isDone)
{
if(asyncLoad.progress >= .9f)
{
// change to bluecolor to indicate now you can continue to next level.
gameObject.GetComponent<Renderer>().material.color = Color.blue;
if(Input.anyKeyDown)
{
asyncLoad.allowSceneActivation = true;
}
}
yield return null;
}
}
As I said this works, but the problem is that I want to freeze the gameplay while this "loading screen" is active. But if I do using "Time.timeScale = 0f" then the coroutine stop working.
Any idea how can I archieve it? Thank you.
Comment