- Home /
Loading screen - Wait for script bool to be true before showing the scene?
Hi. What I'm wondering about is how can I make a loading screen that waits until a script from the scene being 'loaded' is bool true?
I have a public bool called worldGenHasFinished(), that when it's set to true it has finished loading the terrain.
How do I make it like this pattern: MainMenu scene > Loading scene (wait until worldGenHasFinished from world scene) > Load the world scene.
Please let me know if there's anything more you'd like to know or if you misunderstood anything, then I'll try and explain further.
Answer by TranceDreams · Sep 21, 2016 at 10:15 AM
Have you tried using a coroutine?
import UnityEngine.SceneManagement; // must use this in script
function WaitForNewScene(){
while(yourScript.worldGenHasFinished != true ){ yield;}
worldGenHasFinished = true;
SceneManager.LoadScene(nextWorld);
}
I have a Coroutine in the Update() function that then goes to IEnumerator LoadNewScene()
IEnumerator LoadNewScene() {
while (worldGenerator.worldGenHasFinished != true) {
yield return null;
worldGenerator.worldGenHasFinished = true;
Scene$$anonymous$$anager.LoadScene(scene);
}
This doesn't work. How can I get the WorldGen to "get the call" to the loading scene so that it runs?
I'm not getting the Debug.Log message from the script that tells that WorldGen is working.
I called the WorldGenerator script and then got the component of it in the Start() function
private WorldGenerator worldGenerator;
void Start() {
worldGenerator = GetComponent<WorldGenerator> ();
}
The WorldGenerator script has a Coroutine aswell that starts the whole process, maybe that's what I need to call? Not sure how you call a Coroutine though.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Can't Set Animator Boolean Parameter C# 1 Answer
Keep boolean true whilst playing animation, then false 1 Answer
How to fluently transition into an animation state? 0 Answers