- Home /
Simple index out of range question?
Hello guys I have a very simple problem here:
var x = Input.touches[0].deltaPosition.x * rotateSpeed * Time.deltaTime;
its a line of a code that orbits around my character, but it throws the error "index out of range", I figured out that it was because Input.touches[0] can be exceeded but how can I prevent my code from doing that?
something like: if(Input.touchCount > 0){here something}
probably?
Comment
Best Answer
Answer by rutter · Apr 03, 2012 at 03:57 AM
That's exactly it, actually. touches[0]
doesn't exist if the player isn't currently touching the screen. Checking touchCount
beforehand will allow you to access the array safely.
Your answer
![](https://koobas.hobune.stream/wayback/20220613065802im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Simple index out of range question? 1 Answer
IndexOutOfRangeException 1 Answer
Array index is out of Range!? 1 Answer
Random object, Array index out of range 0 Answers
Wierd Animation Bug 0 Answers