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 :slight_smile:

tnx a lot!

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)