- Home /
Iphone touches, Array index is out of range
Hi folks!!!
I'm around an iphone game where you control your player by tapping a left and a right arrow (gui elements)
what I want is to jump with this method: if you are touching an arrow and you touch an leave the other, the player jump!
this is my code and it works but I got an "Array index is out of range" message:
if (Input.touchCount > 0 )
{
var touch : Touch;
if (Input.touches[0].phase == TouchPhase.Stationary && RightButton.HitTest(Input.touches[0].position))
{
//move right
}
if (Input.touches[0].phase == TouchPhase.Stationary && LeftButton.HitTest(Input.touches[0].position))
{
//move left
}
if (Input.touches[0].phase == TouchPhase.Stationary && Input.touches[1].phase == TouchPhase.Ended)
{
//jump
}
}
that's all :)
tnx a lot!
Answer by DaveA · Nov 15, 2011 at 01:29 AM
Input.touches[1].phase : There is no guarantee that there will be 2 touches going, so you need to protect that statement with if (Input.touchCount > 1)
Your answer
Follow this Question
Related Questions
ray=Camera.main.ScreenPointToRay(Input.touches[0].position); 1 Answer
move a GameObject based on Input.GetTouch 1 Answer
From Input.GetMouse to Input.touch. Multi-touch and raycasts? 1 Answer
Detecting RayCast on moving object? 4 Answers
How to prevent infinite loop when Array Index Is Out Of Range 2 Answers