Dynamic increment and build scene in Unity3d

Source: Internet
Author: User

In Unity3d, the scene is mostly done by clicking Add Current in the build settings or by dragging the scene into the panel, and if you don't, your scene will not be loaded, even if you make an absolute path.

that is, the number of scenes to be loaded in a game is mostly fixed. " Dog planing Learning net "


Such a method will have a lot of inconvenience, not easy to dynamically load the scene. So what we're going to say today is a way to load the scene dynamically.


First, you need an editor file, placed under the editor folder. Note that this file cannot be inherited from Monobehaviour


    1. public class buildsceneeditor{[@MenuItem ("build/buildwebplayerstreamed")] static void Build () {string[] levels = new STR ing[]{"Assets/level1.unity", "assets/level2.unity"}; Buildpipeline.buildstreamedsceneassetbundle (Levels, "Streamed.unity3d", Buildtarget.webplayer); } }
Copy Code

In this way, a button appears in your Unity editor, you execute this button, you will appear in your assets sibling directory in your build good Streamed.unity3d file, you put the file on the server, the next step is to download the file and build.


    1. WWW download = WWW.LoadFromCacheOrDownload ("Http://xxx/streamed.unity3d", 0); yield return download; Application.loadlevel ("Level1");
Copy Code

have you noticed that? Download good after you can directly loadlevel, do not need to manually add current operation.

Dynamic increment and build scene in Unity3d

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.