Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Eco-Editor · May 26, 2019 at 09:53 AM · scenescene-loadingloadingmanagerbar

How to have the scene load after a few seconds

Hello all,

I have a loading screen in my project and I want it to appear for a few seconds while unity load the next scene asynchronously. this is the original method I had:

     IEnumerator LoadAsynchronously(int currentSceneNumber)
     {
         AsyncOperation operation = SceneManager.LoadSceneAsync(currentSceneNumber);
         loadingScreen.SetActive(true);
         while (!operation.isDone)
         {
             float progress = Mathf.Clamp01(operation.progress / .9f);
             progressText.text = progress * 100f + "%";
             yield return null;
         }
         loadingScreen.SetActive(false);
         canvas.worldCamera = Camera.main;
     }

I need the script to do the following:

  1. on button press: enable loading screen and start loading the next scene but not yet activate it

  2. start the 2 seconds timer

  3. disable the loading screen and activate the next scene after 2 seconds

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Hellium · May 26, 2019 at 10:03 AM

  IEnumerator LoadAsynchronously(int currentSceneNumber)
  {
      float loadingStartTime = Time.time;
      AsyncOperation operation = SceneManager.LoadSceneAsync(currentSceneNumber);
      loadingScreen.SetActive(true);
      while (!operation.isDone || (Time.time - loadingStartTime) < 2f)
      {
          float progress = Mathf.Clamp01(operation.progress / .9f);
          progressText.text = progress * 100f + "%";
          yield return null;
      }
      loadingScreen.SetActive(false);
      canvas.worldCamera = Camera.main;
  }
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Eco-Editor · May 26, 2019 at 11:13 AM 0
Share

Thanks @Hellium for the quick reply. I don't see bigger difference when using this method. I guess what really counts here is the $$anonymous$$athf.Clamp01 and the fact that even when asyncloading the loading it is making app "lag"

$$anonymous$$y goal is to achieve async loading while the player doesn't "feel" the loading. Assume that the loading will take up to two seconds. On button press - immediately set active the "loading screen" and let it load for two seconds - see the progress text output go from 0%- 100% during this time. $$anonymous$$eanwhile load the scene async but do this while the % of loading shown.

$$anonymous$$y best solution would be that there two variables: float = 2f or actual operation.progress duration.

Check which is longer and choose this one.

this way I ensure that the loading screen appears for at least two seconds and on the other hand if the loading of the scene takes longer than I still have time with the loading screen.

avatar image Hellium Eco-Editor · May 26, 2019 at 11:37 AM 0
Share

It seems I've made a mistake in the condition of the while. Try to replace && by ||.

avatar image Eco-Editor Hellium · May 27, 2019 at 10:56 AM 0
Share

Hi @Hellium replacing && with || can actually be tricky because or condition means that if one of the conditionals is correct then while loop will play... right? Trying that.

I think it's best to find a way to condition the while loop with fixed time also I wonder whether I can know the operation.progress ahead

and also use the operation.allowSceneActivation = false; and operation.allowSceneActivation = true;

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

131 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to select scene based on device screen size? 1 Answer

LoadSceneMode.Single seems to be not working. 0 Answers

Loading Screen? 6 Answers

Load all scenes on begning.... 1 Answer

Why does loading the scene not work? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges