iPhone script reference

I finished my game in pc, now I want it available for iPhone. But I don’t know how to find script, example for iPhone developer and I also don’t know how to test my game. Be it must tested on iPhone?

For example, I have a button and a script attached to it:
function OnMouseDown () {
Application.LoadLevel(“__Menu”);
}

How can I replace this function to make it runs on iPhone?
thanks in advance!

The code is exactly the same, exception is that all OnMouseXXX events don’t exist.
you need to use Update and then check Input.touches or the touchCount variable.

The documentation does actually cover input for iOS: Unity - Manual: Input

–Eric

Thanks so much. But this code not work correctly because when I touch anywhere on the screen, the level __Menu will be always loaded.
function Update() {
for (var touch : Touch in Input.touches) {
if (touch.phase == TouchPhase.Began) {
Application.LoadLevel(“__Menu”);
break;
}
}
}
this script is attach to ButtonGuiTexture. I wanna touch on it then the __Menu scene will be loaded.

I found the solution.
function Update() {
for (var touch : Touch in Input.touches) {
if (gameObject.guiTexture.HitTest(touch.position)) {
Application.LoadLevel(“__GamePlay”);
}
}
}
But I got the trouble. I’m in the Menu scene, then I touch on Play button to load the __GamePlay scene (using above script), but I don’t know why the __GamePlay scene still get my touch (on Menu scene) although I touch only one.

No one help me out?:frowning:

actually the mouse stuff works perfectly on iphone, just saying. Unity actually handles mouse conversion really gracefully to the extent of averaging touches as well :slight_smile:

I’ve found the solution.

function Update() {
for (var touch : Touch in Input.touches) {
if (gameObject.guiTexture.HitTest(touch.position)) {
if (touch.phase == TouchPhase.Ended) {
Application.LoadLevel(“__GamePlay”);
}
}
}
}