This article is a result of work of many other developers and blog post of Unity itself about integration with Android. I wrote this article so that it can help beginners to get their project started with integrating unity and android.
In this article, we will be doing a step by step procedure of exporting a Unity project as an Android source code and then using that as library into our native Kotlin Android app. We will create a simple Unity application and embed it in the Android app. We will also do communication from Android to Unity and Unity to Android as well.
Create a simple unity application and export it as a Android Source. Please note that I’ve used the Unity Version **2019.3.9f1. **Any version above this should also be okay. Please install the Android support modules for the same version if not already present.
These modules should be installed with your Unity version of choice.
New Project window for the Unity Hub
For the unity project, lets add a 3D cube into the sample scene. We want this cube to be self rotating. For its rotation we will need to create a script and attach it to the 3D cube. We can also create a new material and attach it to the 3D cube for changing its color. Create a new script called CubeRotate.
public class CubeRotate : MonoBehaviour
{
private Rigidbody rigidbody;
void Start()
{
rigidbody = GetComponent<Rigidbody>();
rigidbody.angularVelocity = Random.insideUnitSphere;
}
}
#android #unity #kotlin #developer