- 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 Ipsquiggle · Apr 01, 2012 at 09:54 PM
Yes, the simplest solution would be to wrap this in a check, like
if ( Input.touches.Length > 0 ) {
var x = Input.touches[0].deltaPosition.x * rotateSpeed * Time.deltaTime;
// .. more code
}
Your answer
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