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
1
Question by laurienash · Jun 21, 2016 at 11:43 PM · asyncloadlevelasyncprogressprogress bar

Move an object from start to end position depending on the progress of loadlevel..async

Hi,

I'm using loadlevel.async to load my game from the start screen. Whilst the level is loading I would like an object to be set to active which moves from a set start to finish position - but does this depending on the progress of the loading. (So it kind of works like a progress bar, where a 20% fill is 20% loaded level -- but instead I'd like the 20% fill to mean the object has moved 20% across this set distance.

It doesn't have to be super exact - just roughly right.

However - I'm having two problems. The first is that in my console Debug.Log(async.progress) only ever reads 0, and then 1 on loading. (I read online that if I multiply this by 100 this would sort out the issue of it rounding the float number, but I'm still not seeing any change.

Secondly: does anyone have any pointers on how I would achieve this, I'm a bit stuck!

     void OnSwipeUp()
     {
         StartCoroutine (LoadMainLevel());
     }
 
     public IEnumerator LoadMainLevel()
     {
         AsyncOperation async = Application.LoadLevelAsync(1);
 
         float t = async.progress;
 
         overlayTerrain.SetActive (true);
 
             overlayTerrain.transform.position = Vector3.Lerp(startPos, endPos, t);
     
         Debug.Log (async.progress *100f);
         yield return async;
     }
 }

Best, Laurien

Comment
Add comment · Show 1
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 JasonSic · Jun 22, 2016 at 02:05 AM 0
Share

I don't know anything about AsyncOperation, but I do know how move an object from start to end based on your percentage.

Use Vector3.Lerp: https://docs.unity3d.com/ScriptReference/Vector3.Lerp.html

 progressBar.transform.position = Vector3.Lerp(startPosition, endPosition, loadProgress);

"loadProgress" is a percentage but must be between 0 and 1.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by SarperS · Jun 22, 2016 at 04:49 AM

 private IEnumerator LoadScene(string sceneName) {
     // Wait a single frame so the frame gets rendered (required if this method is called in Awake or Start)
     yield return null;
 
     // Start the loading operation
     var loadingOperation = Application.LoadLevelAsync(sceneName);
 
     while(!loadingOperation.isDone) {
         overlayTerrain.transform.position = Vector3.Lerp(startPos, endPos, loadingOperation.progress);
         yield return null;
     }
 
     yield return loadingOperation;
 }
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 laurienash · Jun 22, 2016 at 12:27 PM 0
Share

Hi - that's great thanks!
I'm still having the problem that the .progress is reading 0 all the time while the level is loading, so the game object doesn't move until the last frame when the level has loaded.

Have you had any problems with the .progress not working?

avatar image SarperS laurienash · Jun 22, 2016 at 12:36 PM 0
Share

Nope, works fine on my end. One possible problem that I can think of would occur if you invoke this coroutine multiple times. Try this to run it only once;

 private IEnumerator loadCoroutine;
 
 void OnSwipeUp() {
     if (loadCoroutine == null) {
         loadCoroutine = LoadScene("Your_Scene_Name_Here");
         StartCoroutine(loadCoroutine);
     }
 }

avatar image laurienash SarperS · Jun 22, 2016 at 06:42 PM 0
Share

That's great - it's working (in a build rather than through Unity remote).

It seems to be a bit unreliable - it goes slowly from 0 - 0.3 and then jumps to 0.9, so I might have to fake it by estimating the time ins$$anonymous$$d?

Show more comments

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

45 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

Related Questions

Loading Bar in Different Scenes 1 Answer

How to load levels with animation GUI 1 Answer

Loading Bar for Awake Function 1 Answer

LoadLevelAsync doesn't work as it should 2 Answers

How works loadLevelAsync 0 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