Here are the next two videos in the series:
The rest of the videos can be found here
A little soapbox for me to stand on and rant from.
Here are the next two videos in the series:
The rest of the videos can be found here
After much delay I’ve finally started recording a series of videos on creating a 2D game using Unity. Here are the first two videos. If you want to play the game then check out the Run Bunny, Run! website
Watch all the videos in the series here
This is a quick, step by step guide to creating a simple 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 running on your Android device.
To create an Android app you need to install the Android SDK, which can be downloaded from here. I installed the SDK to c:\android-sdk
If you don’t have a Java Developer Kit (JDK) you will need to download one from here before you can install the Android SDK.
Once the SDK is installed, you need to add the Android 5.01 (API level 21) package to it. Run the SDK Manager and use it to download the API level 21 packages (it should all be selected by default). See here for more info.
Next, 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 so you are much better off testing on a real device. If you are using a “Nexus” device you can install its USB drivers using the SDK Manager, otherwise you will need to install your device’s specific drivers. See here for more info on setting up your USB driver.
You will need to enable USB debugging for your device. On Android 4.2 and higher, the Developer options screen is hidden by default. To make it visible, go to Settings -> About phone and tap Build number seven times. Return to the previous screen and select Developer options at the bottom and turn on USB debugging. On older versions of Android, go to Settings -> Applications -> Development and turn on USB debugging.
To test that everything is set up, plugin in your device, open a cmd prompt and run the following commands :
cd \android-sdk\platform-tools
adb devices</pre>
Your plugged in device should be listed. If not check your device as it may be prompting you to authorize your PC.
Download and install Unity 3D to its default location. The installer can be downloaded from here. Run Unity after the install is complete. You will need to create/login into a Unity account when you first run Unity.
Also, if you have never installed Unity before on your PC you will also be given the option to run Unity Pro for an evaluation period or to run the Free edition. This tutorial only requires the Free version of Unity and I suggest you start with the Free version. You can always upgrade at a later date. You can compare the different versions of Unity here.
Start Unity and select Create New Project in the Project Wizard, name the project RedCube and click Create (if you already have a project open, select File -> New Project to create a new project).
In the drop-down box in the upper right of the screen make sure 4 Split is selected.
From the GameObject menu select 3D Object 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:
Select the Main Camera in the Hierarchy panel and set the following properties for the camera in the Inspector panel:
From the GameObject menu, select Light and then Point light. Set the following properties for the light:
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 :)
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.
Right click on the Assets folder 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 panels. If you are only seeing a wireframe outline of your cube in the Scene panels, select Textured from the Scene panel drop down menu that says Wireframe.
In Unity, scripts are used to add behaviors to objects and to create the logic of your game. We will use a script to make the cube spin.
Right click on the Assets folder 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 onto Cube in the Hierarchy window. Click on Cube in the Hierarchy panel. In the Inspector panel you should see that the cube now has the Spin script (and the RedMat) assigned to it.
Press the Play button. You should now see a red cube spinning in the Game window. Press Play again to stop the game.
Now that we have the app completed, we need to build it for Android.
Select Edit -> Project Settings -> Player
In the Inspector window under Cursor Hotspot click on the tab with the Android icon (4th tab along).
In the Other Settings section change the following values:
Now, select Edit -> Preferences and then select the External Tools section. Click on the Browse button next to Android SDK location and select the root folder of your Android SDK install (c:\android-sdk 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 followed by 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 !
If you are interested in creating 2D games with Unity then check out my Run Bunny, Run! tutorial series.
Otherwise go and complete the some of the Unity tutorials. These will give you a good understanding of how Unity works. Also check out the very comprehensive documentation and the very helpful community.
Have fun :)
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 the camera
Select the Main Camera in the Hierarchy panel and set the following properties for the camera in the Inspector panel:
Add a light
From the GameObject menu, select _Create Other _and then Point light. Set the following properties for the light:
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:
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