Hadi
Hadi

Reputation: 520

Integrating two Unity projects in an Android application

I'm developing an Android app and I need to integrate Unity games/screens in it. I've already exported and added one Unity scene/project to my android app but I cannot figure out how to add two.

I found two main approaches to this:

  1. Create two separate projects: If I do this they clash either in the manifest or in the libraries/assets folder and unity ends up calling just one scene. For reference:

How to correctly import multiple unity module in single android app avoiding name conflict between different unity module in android studio?

  1. I also tried creating one Unity project with multiple scenes and use messages to call the required scene from Android. For me, Android still calls the same scene regardless of which button is pressed. Reference: https://stackoverflow.com/a/43224821/2617578

Does anyone have a solution for this? Either one of the solutions mentioned above would be okay for me.

I'm experienced in Android but a beginner in Unity so I think I might be doing something wrong in the unity code.

I have the unity projects and Android apps I created for the second approach in the following git repository.

https://github.com/hadi-mehmood/AndroidUnityIntegrationSample

Upvotes: 2

Views: 1906

Answers (1)

AminSojoudi
AminSojoudi

Reputation: 2016

Here is one solution to your problem:

First, All things happen inside unity are in one activity.

  • Combine two unity projects and make different scenes for each of them
  • create a empty loading scene that starts first (using unity BuildSettings) and does not do anything
  • on the loading scene, write a SceneLoader script to wait for a command to load a minigame scene.
  • you can pass the scene name using this method UnityPlayer. UnitySendMessage("Gameobject Name","Method","Message")
  • right after running Unity Activity call the method above and it should do the work.

Sample SceneLoader:

public class MySceneLoader : MonoBehaviour
{

    private void LoadScene(string sceneName)
    {
        SceneManager.LoadScene(sceneName);
    }
}

Upvotes: 2

Related Questions