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 Stormize · Oct 14, 2015 at 01:10 AM · c#2dresourcesloading screen

How to make a dynamic loading scene?

So I searched for this a lot, but most of the answers were not what I was looking for and the others were just going over my head. So I have created a scene called "loading" and have animations and all the required stuff here. I want this scene to show every time I switch from one scene to another. I have 3 other scenes called "main", " menu" and "store" and I want to add that loading scene between these. I can't workout how can I do this. Also I wanna know how can I make the things load during the loading screen so that they don't have to be loaded later on. Thank you, let me know if I am not clear anywhere :)

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
1

Answer by fafase · Oct 14, 2015 at 04:24 AM

 public void HandleSwitchLevel(){
      StartCoroutine(Loading("Level"));
 }
 private bool loadingItem = false;
 IEnumerator Loading(string level){
       this.loadingItem = true;
       while(loadingItem){
            Animate();
           yield return null;
      }
      Application.LoadLevel(level);
 }

Add the method as listener to your scene buttons, I guess the player can change scene via a button press.

If you need to perform other actions then add them also as listener. If you need to wait for those action to be done while loading then you need to create a connection between Loading and the other method. Using an event is most likely.

 public UnityEvent OnLoaded;
 public void MethodLoadingItemsForStore(){
        StartCoroutine(LoadingForStore());
 }
 IEnumerator LoadingForStore(){
      while(loadingStuff){yield return null;}
     OnLoaded.Invoke();
 }

And your other class with Loading is registered to OnLoaded with that method:

 public void HandleOnLoaded(){
     loadingItem = false;
 }

Comment
Add comment · Show 5 · 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 Stormize · Oct 14, 2015 at 04:31 AM 0
Share

Great, I will try it asap. BTW, in your first code part, when a button is pressed, can it not switch to a scene called "loading" and switch to "level" string after things have loaded. Also, how do I make the things load. I have added everything I want to load to Resources folder, do I simply use Resources.Load()? Thanks

avatar image Stormize · Oct 14, 2015 at 05:28 AM 0
Share

Okay so in the first code, I tried it. But the thing is, it keeps loading forever and never switches from while loop to Application.LoadLevel(level) below that. I tried doing Debug.log("loading"); in while loop and realised it kept going on forever and never switched to the scene I wanted it to (restart).

About the second code, I can't seem to get the OnLoaded work, basically I don't find "UnityEvent". Do I need to include a namespace?

Thanks

avatar image fafase · Oct 14, 2015 at 05:32 AM 1
Share

Yes, you need a namespace. Right click on UnityEvent then resolve and using (don't remember the namespace, probably some UnityEngine.EventSystem).

Then the event will show in the inspector and you can drag an object and select the method, just as you did for the button.

The loading will not stop since there is no condition to make it stop. This is why you need the second class.

You could have something in Animate() that defines when to switch but it would be arbitrary while you want all other things to be done and then switch.

$$anonymous$$akes sense?

avatar image Stormize fafase · Oct 14, 2015 at 05:57 AM 0
Share

I am still unable to get it to work :/ Okay here's the detail :

I have a scene called "main" where all the things happen. This scene has a restart button and a goto menu button which do their respective functions. However, when switching between scenes the game freezes for a while, ofcourse for loading stuff. Therefore I want a loading screen between them.

So, in my "main" scene, I have a gameObject called "UI$$anonymous$$anager" which is attached to a script called "UI$$anonymous$$anager" and a "LoadControl" gameObject attached to a script called "LoadingScript".

EDIT EDIT EDIT : Please ignore some of the above written things. I forgot to call HandleRestartLevel() in my script. But now that I have done it, the level still won't stop loading and keeps loading forever. Basically, the "loading" scene keeps going forever. in "UI$$anonymous$$anager" //restarting level public void restartLevel() { loadScript.HandleRestartLevel (); }

in "LoadingScript" public void HandleRestartLevel() { StartCoroutine(Loading("main")); }

     private bool loadingItem = false;
     
     IEnumerator Loading(string level)
     {
         this.loadingItem = true;
         
         while (loadingItem) {
             Application.LoadLevel("loading");
             yield return null;
         }
         OnLoaded.Invoke ();
         Application.LoadLevel (level);
         loadingItem = false;
 
 
     }
avatar image fafase · Oct 14, 2015 at 11:41 AM 0
Share

Once you got it all done elsewhere, that is all of the loading of items, then you need to call a method on that object to stop the loading by setting isLoading to false.

Note that if you are not doing the other actions in coroutine then this is pointless as the other actions will keep things hanging.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

How to break a sprite into shapes with script 1 Answer

Why is my character strafing around the mouse (2d) 1 Answer

Simple Jump Script Help 1 Answer


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