Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
This question was closed May 23, 2013 at 12:02 PM by sona.viswam for the following reason:

The question is answered, right answer was accepted

avatar image
5
Question by sona.viswam · May 16, 2013 at 10:22 AM · image

How to make a progress bar for loading next scene

i have 2 scenes in my game

i wish to make a progress bar in first scene according to waiting time to load second scene.

How can i do it with progrss bar.

Is anty other method with image to do it?

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

2 Replies

  • Sort: 
avatar image
12
Best Answer

Answer by TonyLi · May 21, 2013 at 06:14 PM

Calling LoadLevelAsync like TheDarkVoid suggested will start the loading process. You could put it in a coroutine so other parts of the game can keep running. It returns an AsyncOperation. You can check 'isDone' to see if it's done, or 'progress' to get the progress (0-1). Note that progress doesn't work well in the editor, but is more accurate in builds.

Then you need to display the progress. Using Unity GUI, you can draw two textures: one for the empty bar background, and one for the filled progress.

 public Texture2D emptyProgressBar; // Set this in inspector.
 public Texture2D fullProgressBar; // Set this in inspector.
 
 private AsyncOperation async = null; // When assigned, load is in progress.

 private IEnumerator LoadALevel(string levelName) {
     async = Application.LoadLevelAsync(levelName);
     yield return async;
 }

 void OnGUI() {
     if (async != null) {
         GUI.DrawTexture(Rect(0, 0, 100, 50), emptyProgressBar);
         GUI.DrawTexture(Rect(0, 0, 100 * async.progress, 50), fullProgressBar);
     }
 }

  • Note 1: Untested code; may contain syntax errors.

  • Note 2: The example code draws the progress bar at (0,0)-(100,50). Change this to wherever you want to put the bar.

Comment
Add comment · Show 2 · 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 TonyLi · May 22, 2013 at 12:49 PM 1
Share
 void OnGUI() {
     if (async != null) {
         GUI.DrawTexture(Rect(0, 0, 100, 50), emptyProgressBar);
         GUI.DrawTexture(Rect(0, 0, 100 * async.progress, 50), fullProgressBar);
         GUI.skin.label.alignment = TextAnchor.$$anonymous$$iddleCenter;
         GUI.Label(Rect(0, 0, 100, 50), string.Format("{0:N0}%", async.progress * 100f));
     }
 }


Please read: http://docs.unity3d.com/Documentation/Components/GUIScriptingGuide.html

avatar image LoungeKatt · Mar 14, 2014 at 04:03 PM 2
Share

When I tried this, the IEnumerator had to be a generic function outside the call to loading:

 private void SyncLoadLevel(string levelName) {
     async = Application.LoadLevelAsync (levelName);
     Load ();
 }
 
 IEnumerator Load ()
 {
     yield return async;
 }
avatar image
3

Answer by TheDarkVoid · May 16, 2013 at 10:27 AM

Take a look at LoadLevelAsync, it allows you to load a level and still have other stuff going on like a loading screen. It requires unity pro though, as far as i'm aware there's no way to archive this without pro.

Comment
Add comment · 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

Follow this Question

Answers Answers and Comments

17 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

Related Questions

How to create 3D game object in specified pixel size? 2 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

A node in a childnode? 1 Answer

Improve performance of touch script? 0 Answers

Enable / Disable an Image Effect via a button 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