- Home /
Touches, fingerID's and changing them.
Hey everyone. In my code, I have two game objects that move based on the positions of touch 0 and touch 1, however what I'm trying to do is, if touch 0 ends, I'd like touch 1 to be referred to as touch 0.
So, basically, I want one main object to be moved at all times if there are any touches, and if there are two, have the second object move as well. If the first touch is removed, the input from the second touch now controls the first object. Currently it works perfectly fine unless the first touch is removed.
Is there any way to somehow tell the engine that the second touch is now the first? Sorry if this isn't explained very well.
Answer by Owen-Reynolds · Nov 19, 2015 at 02:44 PM
Is there any way to somehow tell the engine that the second touch is now the first?
No. The point of the touchIDs is they never change for a touch. If you get two touches, the IDs are 0 and 1. If the first one lets go, you now have touch[0] with touchID 1. That's important, since you can use the ID to tell that it's the second touch.
The way to do it is to track by touchID, not by position in the touch array. It's one extra step -- search the touches for the correct ID. Instead of the touch[0] dragging the Apple, the touch with ID#0 drags it (which will almost always be touch[0].)
Ah, that makes a lot more sense to me now. Thanks for the answer!
Your answer
Follow this Question
Related Questions
Input.GetTouch(0) doesn't work 2 Answers
Strange touch behavior? 2 Answers
Count a touch in half of screen 2 Answers
2D Raycast touch 1 Answer
Transitioning from different number of touches causes behavior overlap 0 Answers