- Home /
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?
Answer by equalsequals · May 31, 2010 at 09:57 PM
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.
==
Your answer
Follow this Question
Related Questions
How can solve these errors in my java script 1 Answer
3 java errors on a basic shooting script? 2 Answers
Javascript Expecting Errors ';' & '=' 0 Answers
scripting colliders errors 1 Answer
How to display Swipe Marks on iPhone 1 Answer