Check out example codes for "index out of bound unity c#". It will help you in understanding the concepts better.

Code Example 1

// Hey there! oh... you got a bug. but don't worry! I'm here to help you.

// You have this: 
Touch MyTouch = Input.GetTouch(0);

//You need to change it to this:
if (Input.touchCount > 0)
  Touch MyTouch = Input.GetTouch(0);

//Why you ask? because when you say Input.GetTouch(0); the programm thinks there
//is a touch but there is not a touch always, thats why you need to say at first
//if (Input.touchCount > 0) 

//Hope I help you, good luck :)

Learn ReactJs, React Native from