Tutorial: Creating your first Unity Android App
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 :)
Tweet Log – 03-03-2012 to 09-03-2012
- AI designs its own video game http://t.co/iP5bYtFz ->
- The FIRST ever game announcement and gameplay footage from space: Angry Birds Space: http://t.co/ELV3NFDD ->
- TSA Threatens Mainstream Media Not To Cover Story (of bypassable scanners): http://t.co/KAx9cEYl ->
- Raspberry Pi suffers a manufacturing hiccup http://t.co/HEVzKLQg first shipment delayed further ->
- Apple now using OpenStreetMaps instead of Google… but leaves out accreditation http://t.co/Nbnz16Wb ->
- Petridish a Kickstarter for science and exploration projects http://t.co/LMVSdbvr for $5000 you can get a species named after your :-) ->
- From the creators of Twitter comes Branch: A site that hosts useful dialogue http://t.co/aZdLvCQ7 ->
- Biggest Solar Storm In Years Races Toward Earth http://t.co/Dmn5eLjJ ->
- Secure Your Domain – Where Is Safe to Register a Domain Name? http://t.co/27eNwNoV ->
- The (rapid) decline of the media industry: http://t.co/JjCntY94? ->
- AirScape… impressive HTML5 game: http://t.co/QJBx1Ypl ->
- wc -l and grep are your friends…. ->
- mmm new IPad3 is out: http://t.co/ch2AhOGG nothing revolutionary just more of everything ->
- Best Android app evar: http://t.co/fvcvD0lQ (some of the comments are gold) ->
- We're underestimating the risk of human extinction http://t.co/T5qMpWPc ->
- Cool: http://t.co/fTJZNeYT online encyclopedia of writing systems and languages ->
- List of All Countries in All Languages and All Data Formats http://t.co/9MBSyC24 nice work ->
- How easy is it to buy YouTube views? $46 for 20,000! http://t.co/ggSHjYIg ->
- $1B of TSA Nude Body Scanners Made Worthless By Blog — How Anyone Can Get Anything Past The Scanners http://t.co/ypIK8XPj ->
- iPad3 (or 30) concept: http://t.co/VWREqym6 nice CG ->
- There is no point to distributing music in 24-bit/192kHz format: http://t.co/0ctmZeuq ->
- Lots of Android apps for sale today to promote the launch of Google Play: http://t.co/JDhwYllV pity no books, music or movies for NZ users ->
- Font Awesome: The iconic font designed for use with Twitter Bootstrap http://t.co/kxdVmZ7S ->
- Uncle Sam: If It Ends in .Com, It’s .Seizable: http://t.co/rbWFssrx ->
- SQL.js: SQLite Compiled to JavaScript via Emscripten: http://t.co/qpc0Ct8i ->
- More on Google Play http://t.co/BTljTfGx sounds good… if you are in the US and get all the features ->
- Google replaces Android Market with Google Play http://t.co/SJK1BQo7 not sure this is such a good brand play ->
- AIDE write Android apps on your Android device http://t.co/kBqQ9LS8 ->
- Senior LulzSec members grabbed by FBI… given up by group's leader http://t.co/zplfEhBK ->
- 28 Best New Android Games From The Last 2 Weeks http://t.co/kH9e40OA production quality on these is pretty good ->
- Unity3D for iOS and Android free till4 April! Save $800 http://t.co/3qBZFRKQ servers have gone boom ->
- Who Gets the Mobile Money? http://t.co/dtEUNYMf its not the app developers ->
- Square releases and iPad POS app https://t.co/TyIOi3Fa ->
- Nearly half of US adults are smartphone owners http://t.co/DtPSzGme ->
- The Brogrammer??? Seriously??? http://t.co/QkjNOh2g ->
- Ouch: http://t.co/WkIE34Nw #hustonwehavesomeunhappycustomers ->
- Facebook uses <bgsound> to track if you have opened an email: http://t.co/91dsUJJB ->
- RagePixel: pixel art toolkit for Unity: http://t.co/gGtCKMnq ->
- Raspberry Pi for $49 NZD: http://t.co/p2k86gFR lead time of 66 days :( ->
- GitHub and Rails: You have let us all down: http://t.co/K3EfYMcH ->
- Good post on what it takes to make a web app with a iOS look & feel: http://t.co/0MfiWxpK maybe he should have just built a native app? ->
- The iPad is the new IE6? http://t.co/LOXgMXeq ->
- Ceremony done… happy couple are married. Bring on the drinks! ->
- Very cool… aerial swarming robots at TED http://t.co/8BejzNM7 ->
- Grace Hopper To Programmers: Mind Your Nanoseconds! http://t.co/a0HCO29g ->
- iPads using iOS 6, high-res displays showing up in Ars server logs http://t.co/x8HBCkSB ->
- I'm supposed to be at a beach wedding today ….. may get blown out to sea #weatherbomb ->
Tweet Log – 25-02-2012 to 02-03-2012
- Notch gives his $3,000,000 Minecraft dividend to his employees http://t.co/zL4xvZNv ->
- Give it five minutes http://t.co/HtKzYJzC ->
- Netflix Loses Toy Story 3, Tron and 1,000 More Movies http://t.co/cSXexhGQ ->
- ITA rolling out next gen airline platform http://t.co/zXJ6GVDl ->
- Gaia the UI for Mozilla's phone OS https://t.co/LVoXTkea ->
- Windows Azure cloud outage was due to leap year bug! http://t.co/kkTpSTjF ->
- Escape your search engine Filter Bubble: http://t.co/5sdJJwTQ ->
- a 500ms increase in page load time on Google led to 20% less traffic and revenue: http://t.co/yqfx7cV7 #makeitgofaster ->
- Which One: Responsive Design, Device Experiences, or RESS? http://t.co/0wZasI04 (via @wrumsby) ->
- "The indictment focuses on movement of funds outside the US and you can't just "flout US law" by not being in the US" http://t.co/UrISrYyY ->
- Verisign seizes .com domain registered via foreign Registrar on behalf of US Authorities: http://t.co/UrISrYyY ->
- KinectJS JavaScript lib for accessing Kinect in a browser http://t.co/bqNe2DV4 ->
- Aaahhh Raspberry Pi went on sale today http://t.co/u01FSU2W ->
- Signs back on but showing wrong info… IT fail ->
- Trains all fubar. New digital signage cannot cope so they just turn it off… total chaos ->
- Need to look for this on the History Channel: full Metal Jousting: http://t.co/PmNucYpm ->
- 25 alleged Anonymous members busted by Interpol http://t.co/ykrA1Y8x ->
- Company That Issued Bogus TechDirt Takedown Says It Was All A Mistake, Apologizes: http://t.co/d27njeiQ ->
- Just had a play with that Collusion plugin… scary stuff. The media sites seem to be the worst offenders! Red=tracker http://t.co/nPEBq9jL ->
- Very convenient new jQuery Mobile release candidate http://t.co/Yoqay1lR ->
- New stats UI and features for Android dev console http://t.co/51uU6J7r kicks the butt of the Apple tools ->
- Mozilla releases Collusion Firefox plug. shows a real-time graph of 3rd party tracking as you browse the web http://t.co/WIju2pPl ->
- Trains late or cancelled every morning for the last three days… wonder what the hell is going on? ->
- Cool! How to build a USB connected slingshot for playing Angry Birds http://t.co/imgJvQ0H ->
- Balsamiq Mockups now integrated into UX.stackexchange http://t.co/19LJqrsl cool ->
- Interesting to see Wikileaks list @nzherald as one of the 25 media orgs that it has a investigation partnership with: http://t.co/YvS4uG1O ->
- WikiLeaks begins publishing 5 million emails from STRATFOR http://t.co/YvS4uG1O ->
- Just excepted a bunch of linkedin invites…. my profile is looking a little sad… so hate writing about my self; seems so conceited ->
- Android fragmentation data http://t.co/hxKhvfAQ very interesting. Looks like we are in a period of high fragmentation at the moment ->
Tweet Log – 18-02-2012 to 24-02-2012
- Air New Zealand Reports Reduced Profit: http://t.co/faNDklpd :( ->
- Google, Microsoft and Netflix trying to add DRM into HTML5 video spec: http://t.co/CdjP2KaF #badcompanies ->
- Cash Mobs help out struggling local stores http://t.co/eeBwrqG0 ->
- A data driven look at why Facebook commerce is failing http://t.co/IKVelsE2 very interesting numbers ->
- “If bandwidth caps were such a good thing all the top performing countries would use them” http://t.co/cZq5TBJ6 ->
- Video of Ubuntu For Android in action: http://t.co/IA27RH8C looks pretty integrated ->
- Interesting way to fold paper: http://t.co/ESxr75gZ ->
- ok, the Autobahn is cool: http://t.co/YBgQQyrj ->
- EFF Wins Protection for Time Zone Database http://t.co/B7WGsGfO ->
- Study shows 29 percent smartphone owners use their phones as shopping companions http://t.co/W1Y6p8yj ->
- Tons of data on mobile platforms and market shares: http://t.co/vSjCptm1 all very interesting ->
- Platform wars: A history of personal computing http://t.co/Ua4CJ2wX very interesting graph ->
- How to use the Galaxy Nexus as a desktop replacement http://t.co/JFmWWUfZ ->
- Bye bye ACTA? European Commission to ask European Court to check if ACTA is fully compatible with EU fundamental rights http://t.co/nDBJPXpH ->
- Remove your Google search history before new privacy policy takes effect https://t.co/AG0fUGpr #tinfoilhat ->
- Amazon releases simple workflow services for their cloud http://t.co/SaDuKpiI ->
- Flash on Linux will only be available for Chrome from now on? http://t.co/XemfHi8q ->
- VoiceBunny: Fast and professional voiceovers (with an API) http://t.co/Pe3xYjIb ->
- Google to sell HUD glasses by years end? http://t.co/kR2MtazN ->
- Interesting… Ubuntu for Android http://t.co/nFXjVFeg turns your docked Android phone into a PC! ->
- Apache 2.4 server released https://t.co/gd2MDDyp ->
- The 101companies project… the same system created with a 100+ different languages/techs: http://t.co/Ez6KoSjs ->
- RIAA Insists That, Really, The Music Industry Is Collapsing; Reality Shows It's Just The RIAA That's Collapsing http://t.co/AQyf6sw2 #dodos ->
- Tetris in a 140 bytes of JavaScript http://t.co/M0jVMjHi ->
- Galera synchronous multi master replication for MySQL http://t.co/BODKZJEW ->
- WTF just noticed my Intel graphics drivers install size is 1.19GB !!! ->
- having to run my data mining job on a single machine; so sloooowwww…. I miss my hadoop cluster ->
- Physicists Create a Working Transistor From a Single Atom http://t.co/PilceOfe ->
- Telcos call for Crown company to be scrapped http://t.co/ZiSritDQ ->
- Oracle vs Google damages now down from $6.1 billion to $58million and they still may lose http://t.co/9DAyrxXf #googlelawyerswortheverypenny ->
- Facebook Is Losing E-Commerce http://t.co/gFH8kVwR ->
- More charges filed against Dotcom http://t.co/ss3hWDfP ->
- Zynga blatantly releases clone of Indie game? http://t.co/JumLUZK0 shame on them and rigging ratings too! ->
- VLC 2.0 is out http://t.co/vCfOASbt ->
- Jotform domain returned govt refuses to comment on events http://t.co/MVuVRIKj ->
Tweet Log – 11-02-2012 to 17-02-2012
- How Target Figured Out A Teen Girl Was Pregnant Before Her Father Did: http://t.co/LqmKfSGx the scary power of data mining ->
- High Orbits and Slowlorises: understanding the Anonymous attack tools http://t.co/gPxEHUmr also make great load testing tools ->
- Chrome with native Dart support now available: http://t.co/4ibH5Sgi ->
- Interesting micropayment phone app from Barclays UK http://t.co/jKmM8n9g ->
- So you want to be a developer http://t.co/SzG3oYeL ->
- Jotform domain seized for user generated content http://t.co/PXzVZQwC ->
- The machine's view of time, if nanoseconds were seconds: http://t.co/Xe711DAq ->
- iOS to introduce an app permission system like Android? http://t.co/ElIFKXPq ->
- Just been to the house of pain. New hygienist was very rough #havingamancry ->
- http://t.co/yi5ZoT5S drop in color palettes for bootstrap ->
- Wow…. enhancements to content aware fill in the new photoshop http://t.co/8kZr3CTM more reasons to never trust images ->
- apparently there has just been a big tornado/water spout thing on the north shore… ->
- ChefHangout is a genius use of Google+ Hangouts and could actually make money http://t.co/nSIJ6TeL ->
- Unity 3.5 officially released http://t.co/906JaYdH ->
- Laptop made from paper: http://t.co/EsfBTn22 interesting paper based replacement for plastic.. ->
- EU Official Who Resigned Over ACTA Details Why ACTA Is Dangerous: http://t.co/dNLaU7pn ->
- What the… only 2 weeks left of summer http://t.co/oiT1MCYr #crazy ->
- http://t.co/Qtqq8Mr8 free and legal ebooks ->
- BitTorrent Live…. the death of traditional TV ? http://t.co/ucaKHTnF ->
- Apple launches new legal attack on Samsung phones: http://t.co/vXiks9HV #innovatedontlitigate ->
- The good thing about Android is also sometimes the worse thing about Android: http://t.co/boZryRZk ->
- The internet is angry – is it winning? http://t.co/YLzUaxPm ->
- Get Ready for 1 Billion Smartphones by 2016: http://t.co/utisnop6 ->
- Google wins EU okay for Motorola buy: http://t.co/gkS16ys5 ->
- BitTorrent doesn't hurt US box-office, delayed international releases drive downloading: http://t.co/5IYWIQ8e ->
- Totally agree child porn is BAD but I think Reddit is on a slippery censorship slope here: http://t.co/lpzcxuVa ->
- Mobile Sites vs. Apps: The Coming Strategy Shift http://t.co/4rc9sN97 ->
- Wow real-time skin rendering: http://t.co/tqU4ha9p ->
- Wind-up AA battery design: http://t.co/zS705m9L #nice ->
- Documenting a Hadoop/Pig process is seriously painful….. ->
- Kiwi Skeptics… cute marketing campaign by @flyairnz http://t.co/Mm83KoIG ->
- Why Oracle may really be doomed this time http://t.co/3qlSEE0l ->
- ACTA protests in Europe http://t.co/NJsWSgpT ->
- Iran kills access to Internet http://t.co/hVl7sCWo ->
- 30% of all US military aircraft are drones http://t.co/n05gtsOR ->
- Kim Jung Un assassinated outside NK embassy in China??? http://t.co/iQdNqY4p ->
- Documentary on Anonymous http://t.co/Vv5nDq1a ->
- Alan Moore on V for Vendetta and Anonymous http://t.co/ahiQzlIA ->
- Kickstarter: 2 $1million projects in 24hrs http://t.co/XtK6gah5 ->
- Germany decides not to sign ACTA http://t.co/e45ovUcw ->