Invoking scene when loading Unity as subview in Android

前端 未结 1 646
天涯浪人
天涯浪人 2021-01-20 17:49

I have integrated Unity in an Android activity (similar to this). I now need to dynamically load a scene depending on user input.

I\'ve tried replicating how Unity l

相关标签:
1条回答
  • 2021-01-20 18:29

    If you plan to load Unity activity from Android, you should create an empty scene. Call this this Main Menu, then make it the default scene that loads through the Build Settings. Make it index 0.

    The goal of this empty scene is to load specific scene when script attached to it is called.

    In this Main Menu scene, create a GameObject called SceneLoader then attach the script below to it:

    public class SceneLoader : MonoBehaviour
    {
        public void loadScene(string sceneIndex)
        {
            UnityEngine.SceneManagement.SceneManager.LoadScene(Convert.ToInt16(sceneIndex));
        }
    }
    

    You should also create a GameObject called SceneLoader in every other scene and attach the script above to all of them.

    Now, load Unity Activity which automatically loads the default/empty scene. Since there is only one GameObject/SceneLoader in it, it will load very fast.

    You can now load other scenes from Java with:

    UnityPlayer.UnitySendMessage("SceneLoader", "loadScene", "9");
    
    0 讨论(0)
提交回复
热议问题