Unity to Iphone Unity iPhoneTouchPhase.Ended problems

I have the following code that functions properly in unity:

`

var quitbutton= false;

function OnMouseUp() { if(quitbutton) { Application.Quit(); } else { Application.LoadLevel(1); } }

`

But when I change it to this within Iphone Unity:

`
var quitbutton= false;

function iPhoneTouchPhase.Ended() { if(quitbutton) { Application.Quit(); } else { Application.LoadLevel(1); } }

`

I get multiple errors, begining with :

expecting (, found '.'.

';' expected. Insert a semicolon at the end.

Unexpected token: if.

etc. . .

I am trying to get it so when I tap the button it either quits the game or launches the application. What would cause these errors and how would I fix them?

The reason why this does not work is because iPhoneTouchPhase.Ended is part of an enum.

You need to set it up like this: (C#)

void Update()
{
    foreach (iPhoneTouch evt in iPhoneInput.touches)
{
    if(evt.phase == iPhoneTouchPhase.Ended)
    {
          // do whatever
          print("touch ended.");
        }
    }
}

What this does is every frame you are cycling through the touch objects which are automatically cached in iPhoneInput.touches by Unity in communications with the iPhone SDK all behind the scenes.

Now that you have reference to your individual touches, you can check the documentation for iPhoneTouch to see all the properties and methods the object has. You will see that I have a check in there that in any given frame if any touch is in the "Ended" phase it will return true and print "touch ended" to the console.

Hope that clears things up a bit.

==

I worked around the problem using the FingerManager.cs script written by rozgo.

FingerManager.cs can be found here