0
\$\begingroup\$

When I want to load another scene and show my loading screen to the user - my loading screen is a game object holding a canvas, I use coroutines, but when I type something like this: LoadingScreen.Show (); Application.LoadLevel ("PlayerMenu");

Loading screen is shown less than a second, so I wanted to use coroutines, I typed this:

IEnumerator LoadLevel(string levelName) {
    LoadingScreen.Show ();
    yield return new WaitForSeconds (2f);
    Application.LoadLevel (levelName);
}

The problem when calling the coroutine is that my LoadingScreen.Show() code is not executed, so basically I'm just waiting 2 seconds looking at the background of my current scene and then it goes to another scene, I'm confused here as to what is going on, shouldn't my LoadingScreen.Show() code be executed and then I would see the loading screen and wait 2 seconds and the next scene will appear. Anyone has an idea?

\$\endgroup\$
  • \$\begingroup\$ use Debug.Log in LoadingScreen.Show to see if it is getting called. \$\endgroup\$ – zoran404 Apr 6 '15 at 10:15
  • \$\begingroup\$ its called, just did what you said, in LoadingScreen.Show im just setting the images.gameObject.setActive(true) to show the images, i added debug.log in the last line to see if it gets executed and it is executed \$\endgroup\$ – Fahir M Apr 6 '15 at 10:18
1
\$\begingroup\$

If your level is loaded fast, but you want to show a splash screen for a while what you can do is show the splash screen at the end of one level, call LoadLevel right after and have the splash screen shown at the start of the other level.
You should have a variable saying after what time to remove the splash screen.

This way would be much more practical, because you have bigger control of how long it is shown.

Oh and the way I save variables between levels is by using a class with static variables. Because those variables don't change when you switch scenes.

\$\endgroup\$
  • \$\begingroup\$ great thanks, nice idea, just did it and it worked, thank you very much. \$\endgroup\$ – Fahir M Apr 6 '15 at 10:29
  • \$\begingroup\$ glad I could help. Btw I'd recommend using unity's GUI system for the splash screen. It gives you big flexibility in ways to display the image. \$\endgroup\$ – zoran404 Apr 6 '15 at 10:33
  • \$\begingroup\$ yes im using a game object and i added a canvas as a child to it, added 2 images and a text, im just activating and deactivating those images and text when i want to show loading screen \$\endgroup\$ – Fahir M Apr 6 '15 at 10:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.