There are a wealth of resources for Unity iPhone but, when starting out, I would really have appreciated a bunch of step-by-step tutorials showing how to achieve some of the fundamental things that games developers typically need to do. Being able set up an FPS controller in a couple of mouse-clicks is all well and good (in fact it’s awesome) but not much use if you don’t actually want to make an FPS, hence this set of several short tutorials showing how to do some very specific, simple things with Unity iPhone. For anyone approaching Unity from a similar perspective to myself (ie being familiar with the iPhone and other development solutions but only casually acquainted with the engine) this stuff should hopefully help you to hit the ground running.
So, with regards to the iPhone the three questions I wanted immediate answers to were “How do I make a button that will respond to being tapped?”, “How do I pick meshes?” and “What’s the deal with serialisation?” In this tutorial we’ll deal with the first of those:
1: Getting Started
The first thing to do is create a new project. There is no need to import the standard assets for the purposes of this tutorial.

2: Class Acts
We need something to happen when we tap our button so let’s begin by creating a projectile prefab that we can fire. A Unity prefab is akin to a custom type or class in an OOP language.
From the main menu: GameObject>Create Other>Sphere
In the Project View: Create>Prefab
In the Project View:Create>JavaScript
Rename the prefab to ‘Projectile’ and the script to ‘Projectile_AI’.
Drag the sphere from the Hierarchy View and drop it on the Projectile prefab in the Project View (the prefab’s icon will turn solid blue). What we have done here is turn the sphere into a prefab, hence we no longer need the original – ensure only the sphere is selected then press Apple+Backspace to delete it.
3: Oooh Behave!
Now let’s define some behaviours for the Projectile class. Double-click the Projectile_AI script in order to bring up the Unitron editor. Edit the script thus:
var life = 100;
function Update () {
transform.position += Vector3.forward * 1.0;
life -=1;
if (life<1){
Destroy(gameObject);
}
}
Save the script.
Pop back to Unity. Select the Projectile prefab so that you can see its components in the Inspector View, now drag ‘n’ drop Projectile_AI on to the list of components, attaching the script to the prefab. This is a good time to wave your hands majestically and pronounce “Object, I grant thee… BRAINZ!”

You’ll notice that the ‘Life’ variable is exposed to the Inspector View and you can edit it to taste from here.
4: I Got Them Tappy Feet Fingers
Finally, let’s make a button to tap!
From the menu: GameObject>Create Other>GUI Texture
The default image for GUI Textures is the Unity watermark and, hell, it’ll do for now – rename it ‘Button’ and alter its x and y position to 1.5 in the Inspector View, placing it at the bottom-left of the screen.

Next we make a script to govern the GUI Texture’s behaviour. Create a new JavaScript in the Project View, rename it ‘CheckButton’ then double-click it to bring up Unitron. Edit the script thus:
var shot:Transform;
var recoveryTime = 10;
private var delay = 0;
function Update () {
if (delay>0){delay -=1;}
if (delay==0){
if(iPhoneInput.touchCount == 1){
var currentTouch:iPhoneTouch = iPhoneInput.touches[0];
if(currentTouch.phase == iPhoneTouchPhase.Began && guiTexture.HitTest(currentTouch.position)){
var shot = Instantiate(shot, Vector3 (0, 0, 0), Quaternion.identity);
delay = recoveryTime;
}
}
}
}
The above, you will notice, is geared towards single touch input. For multi-touch input we can cycle through any existing touches in a loop, in which case the entire script would look like this:
var shot:Transform;
var recoveryTime = 10;
private var delay = 0;
function Update () {
if (delay>0){delay -=1;}
if (delay==0){
for (var touchIndex = 0; touchIndex<iPhoneInput.touchCount; touchIndex++){
var currentTouch:iPhoneTouch = iPhoneInput.touches[touchIndex];
if(currentTouch.phase == iPhoneTouchPhase.Began && guiTexture.HitTest(currentTouch.position)){
var shot = Instantiate(shot, Vector3 (0, 0, 0), Quaternion.identity);
delay = recoveryTime;
}
}
}
}
Back in Unity, select our Button from the Hierarchy View and drag the CheckButton script onto its list of components (in the Inspector View). You will see that the recoveryTime variable is exposed and can be edited whereas the delay variable, being private, is not. The other exposed variable is ‘Shot’, which is of the Transform type – click on it to get a drop-down list and select ‘Projectile’. This lets the script know what kind of object Shot is meant to be when it is instantiated.

Click Play in the Game View if you are using Unity Remote, or Build & Run if you are opting to deploy straight to your iPod/iPhone (in which case remember to set an appropriate bundle name and nominate landscape mode – From the menu: Edit>Project Settings>Player). Tap on the button and… voila!

Cheers to: arzi and Sergey “Fly” from the Unity forums.