The question is answered, right answer was accepted
Arugument Out of Range - touchScreen
Hi, I'm working on making a multi touch screen game (basically simultaneously moving multiple cubes around the screen with multiple fingers). I have it working, and I am able to move multiple objects - however when I'm moving more than one cube (say two cubes with two fingers) I get this error:
ArgumentOutOfRangeException: Argument is out of range. Parameter name: index System.Collections.Generic.List`1[UnityEngine.GameObject].get_Item (Int32 index) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/List.cs:633) buttonTouch.OnTouchMove () (at Assets/Approach3/buttonTouch.cs:83) UnityEngine.GameObject:SendMessage(String, Object, SendMessageOptions) touchInput:Update() (at Assets/Approach3/touchInput.cs:47)
And yet it still functions and works?! The same error happens if I move three cubes or four cubes, but it doesn't occur when I am moving just one cube.
I'm pretty sure that the bug exists here within the FOR loop or the fingerPosition variable - but I'm not sure and I've tried everything. Please help! This is really bugging me.
Answer by hexagonius · Apr 04, 2017 at 09:05 PM
you're iterating touchCount times and you're using i for accessing touchManager array. they're of different size.
Hi hexagonius, thanks for the clarity clue, I got it to work. I don't know why I didn't see it, I think I was focusing on the Input.touchCount way too much.