Tutorial: Creating your first Unity Android App

This tutorial is out of date. See here for an updated tutorial covering the latest version of Unity.

This is a quick, step by step guide to creating a simple spinning cube app for Android using Unity. This tutorial is for windows but other then the install instructions it should work for other platforms. By the end of this tutorial you will have created an app that displays a red spinning cube on a blue background on your Android device.

Setup Unity

You will need Unity AND the Android feature to create the app. Unity basic is free and the Android feature is currently free till the 8th April 2012 (which saves you $400). Download the installer from here and get your license from here.

Install Unity and register it using your license key which should have been emailed to you.

Setup the Android SDK

To create an Android app you need to install the Android SDK, which can be downloaded from here. I have the SDK installed to c:\android-sdk-windows

Once the SDK is installed you need to add the Android 2.1 (API level 7) package. Run the SDK Manager and use it to download the API level 7 packages. See here for more info.

Lastly, you will need to install the USB device drivers for your Android device. Whilst it is possible to use the Android Emulator its performance is pretty bad (especially when emulating tablets) so you are much better off testing on a real device. If you are using a “Nexus” device you can install USB drivers using the SDK Manager, otherwise search the web for your devices drivers.

To test that everything is set up, plugin in your device, open a cmd prompt and run the following commands :

cd \android-sdk-windows\platform-tools
adb devices

Your plugged in device should be listed. You may have to enable USB debugging for your device. Go to Settings -> Applications -> Development and turn on USB debugging.

Creating the app

Start Unity and select File -> New Project to create a new project, name the project RedCube.

In the drop-down box in the upper right of the screen make sure 4 Split is selected.

Create the cube

From the GameObject menu select Create Other and then select Cube. Make sure that Cube is selected in the Hierarchy panel (3rd panel along the top of the screen), then in the Inspector panel (far right panel) set the following values for the cube:

  • Position: x = 0, y = 0, z = 0
  • Rotation: x = 0, y = 45, z = 45
  • Scale: x = 2, y = 2, z = 2

Position the camera

Select the Main Camera  in the Hierarchy panel and set the following properties for the camera in the Inspector panel:

  • Position: x = 0, y = 0, z = -5

Add a light

From the GameObject menu, select _Create Other _and then Point light. Set the following properties for the light:

  • Position: x = 0, y = 0, z = -5

Test the scene

Click on the Play button (top center of the screen). You should now see the lower left panel switch to the Game tab and you should see a white cube on a blue background.

Press the Play button again to stop the game.

Note this important! Unity allows you to make changes whilst the game is running but these changes are lost as soon as you stop the game running. This is great for debugging but is an easy way to lose you changes :)

Save your project

Speaking of losing your work, now is a good time to save your project. Select File -> Save Scene, enter RedCubeScene as the name for the scene when prompted. Then select File -> Save Project to save the project. Remember to save your work regularly.

Making the cube red

Right click in the Project panel (3rd along the bottom) and then select Create -> Material, name it RedMat. In the Inspector window click on the white color block next to Main Color and then select a red color from the color picker. Drag the RedMat material from the Project window onto Cube  in the Hierarchy window. The cube should now turn red in the various scene windows.

Making the cube spin

In Unity scripts are used to add behavious to objects and to create the logic of your game. We will use a script to make the cube spin.

Right click in the Project panel and select Create -> C# Script, name it Spin.

In the Inspector window click the Open button, give it a moment for the MonoDevelop IDE to launch. You should see a code editor window. Modify the code to read as follows:

using UnityEngine;
using System.Collections;

public class Spin : MonoBehaviour {
    // Use this for initialization
    void Start () {

    // Update is called once per frame
    void Update () {
        // rotate at 90 degrees per second
        transform.Rotate(Vector3.up * Time.deltaTime*90);

Save the code (press Ctrl+S) and then switch back to the Unity editor.

Drag the Spin script from the Project window on to Cube in the Hierachy window.

Press the Play button. You should now see a red cube spinning in the Game window. Press Play again to stop the game.

Building the app

Now that we have the app completed, we need to build it.

Select Edit -> Project Settings -> Player

In the Inspector window under the Per-Platform Settings click on the tab with the Android icon (3rd tab along).

In the Other Settings section change the following values:

  • Bundle Identifier = com.rabidgremlin.tut.redcube
  • Minimum API Level = Android 2.1 ‘Eclair’ (API Level 7)

Now, select File -> Preferences and then select the External Tools section. Click on the button next to Android SDK location and select the root folder of your Android SDK install (c:\android-sdk-windows in my case).

Next plug-in your device.

Now, select File -> Build & Run, this will open the Build Settings window. Select  Android under platform and then click on the Build & Run button, when prompted for a name for the .apk file enter in RedCube.

A build dialog will pop up and you will see the app being built, then you will see a message about the app getting pushed to your device.

Have a look at your device, you should see the RedCube app starting up, followed by a red cube spinning on a blue background.

Congratulations you have created your first Unity Android app !

What next?

First off go and complete the 3D platform game tutorial. This will give you a good understanding of how Unity works. Also check out the very comprehensive documentation and the very helpful community.

Now go nuts :)

Update: If you are interested in creating 2D games with Unity check out my Dev Diary for my game Word War III