Unity Loading Scenarios Asynchronously

Source: Internet
Author: User

As follows:

Today has been tangled in how to load the scene, the middle of the loading screen and the effect of loading finished animation!

A scene to B, see online practice is a–> c–> B. C scenes are primarily used to asynchronously load B and play some animations of loading scenes

asyncoperation op = Application.loadlevelasync ("C"); Loading C scenes asynchronously

op.allowsceneactivation = false; Do not automatically jump to the B scene after loading (at the end of loading, you can play some loaded animation) when the animation is finished playing

op.allowsceneactivation = true; You'll be able to enter the B scene. O (∩_∩) o~

op.progress; gets the actual progress value of the asynchronous load scene (0-1)

usingUnityengine;usingSystem.Collections; Public classLoadsceneb:monobehaviour { PublicUISlider Slider;//progress bar    voidStart () {loadgame (); }         Public voidLoadgame () {Startcoroutine (startloading ("C")); }     PublicIEnumerator startloading (stringscenename) {asyncoperation op=Application.loadlevelasync (scenename); Op.allowsceneactivation=false; /*actual progress is based on the scene loading, while (Op.progress < 0.9f) {slider.value = op.progress;        The progress value of the actual loading scene is displayed in the slider. Yield return new waitforendofframe (); }*/        //since the C scene has only one picture loaded too fast, the following code simulates loading         for(inti =0; I < -; i++) {Slider.value= I/100f; yield return NewWaitforseconds (0.01f); } slider.value=1; yield return NewWaitforendofframe (); Op.allowsceneactivation=true; }}

Unity Loading Scenarios Asynchronously

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.