简体   繁体   中英

Call scene in Unity from Android plugin

I have Unity application that is called from another Android application via app links. So, I've created Android Plugin for Unity to handle params sent to app via url. Depending on data from url I want to load one of three scenes defined in my Unity application. I was trying to call gameobject from scene no2 but I've got error: Object not found and scene no0 is loaded.

This is call from Android plugin to Unity:

UnityPlayer.UnitySendMessage("ARCamera", "startScene", "some data");

It looks like Unity is looking for ARCamera in scene no0 and it is not there, of course. Is it possibile to call scene that is not defined as starting (0) in Build settings? How?

EDIT:

In android:

public void startAppP() {
        Log.v(TAG, "starting p");
        UnityPlayer.UnitySendMessage("ARCameraP", "loadScene", "sceneP");
    }

and in Unity (scene defined as no3) in script attached on object called ARCameraP:

public void loadScene(string sceneName)
{
    UnityEngine.Debug.Log("HI");
    Application.LoadLevel(sceneName);
}

It keeps returning SendMessage: object ARCameraP not found!

I am using older version of Unity because I had some problems with Vuforia. Camera was showing black screen until I downgraded Unity to version 5.1.2.

You can load default scene with by passing in 0 to SceneManager.LoadScene(0); but you can't use the string overload version of the method SceneManager.LoadScene("defaultScene"); until you add the scene in the Build Settings .

C# code:

public void loadScene(string sceneName)
{
    SceneManager.LoadScene(sceneName);
}

Java code:

UnityPlayer.UnitySendMessage("NameOfGameObject", "loadScene", "sceneName");

Make sure that Scene names are added to the Build Settings. If they are not then use SceneManager.LoadScene(0);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM