- Home /
ray=Camera.main.ScreenPointToRay(Input.touches[0].position);
IndexOutOfRangeException: Array index is out of range. accelerometer.Update () (at Assets/Standard Assets (Mobile)/Scripts/accelerometer.cs:36) Why?
Comment
Best Answer
Answer by japanitrat · Sep 09, 2011 at 09:43 AM
well it seems, that there is no touch (Input.touches is empty). You should check the array length before you try to access elements in it:
if(Input.touches.Count > 0)
{
ray = Camera.main.ScreenPointToRay(Input.touches[0].position);
// do stuff ...
}
else
{
Debug.Log("No touches available");
}
This is really wierd, I've started getting this error message too, but the thing is all my references to the Input.touches array are already inside the condition if(Input.touches.Count > 0){ }