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?

1 Answer

1

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");
}

Thank you very much!It's helpful!

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){ }