- Home /
Multi - touch not registering during update.
Hey all,
I have two classes one for character movement and one for character rotation and they work almost identically. I need each class to cache a Touch and recognize when the other class is using a Touch. Here is the code I am trying.
if (MovementBool)
{
if (Input.touchCount > 0)
{
if (Input.touchCount == 1)
{
MovementTouch = Input.GetTouch (0);
if (Pad.Contains (MovementTouch.position))
{
Point.position = MovementTouch.position;
}
else
{
Point.localPosition = Vector2.zero;
}
}
else if (Input.touchCount > 1)
{
MovementTouch = Input.GetTouch (1);
if (Pad.Contains (MovementTouch.position))
{
Point.position = MovementTouch.position;
}
else
{
Point.localPosition = Vector2.zero;
}
}
else
{
Point.localPosition = Vector2.zero;
}
}
else if (Input.GetMouseButton (0))
{
if (Pad.Contains (Input.mousePosition))
{
Point.position = Input.mousePosition;
}
}
else if (Input.GetMouseButtonUp (0))
{
Point.localPosition = Vector2.zero;
}
}
This is all within Update (). Am I mismanaging the touches here?
Thanks
The idea here looks wrong. If there are two touches, it looks like the both use the second, and no one uses the first?
Is it possible to have the only touch be movement OR be rotation? (ex: they can tap the joystick icon is steer w/o moving?) How do you keep track of this?
The touch order is fixed (touch#0 is always rotation) then just say: if touch 0 exists, rotate with it. If touch 1 exists, move with it.
Also, the correct way is to look up the internal touch number. If you have a left and right touch, one frame the left touch may be #0, and next frame it can be #1. But, in practice, this only happens when someone has two touches and lets go of the first (touch 1 is now touch 0, but keeps the same internal touch number.)
Your logic is wrong. Specifically:
if (Input.touchCount == 1)
{
$$anonymous$$ovementTouch = Input.GetTouch (0);
...
}
else if (Input.touchCount > 1)
{
$$anonymous$$ovementTouch = Input.GetTouch (1);
...
in English, "If there's one touch on the screen, use the first touch. Else, if there's more than one touch, use the second touch."...?
@ Owen, I see, so how do I get the internal touch ID? Is that the fingerID value?
Your answer
![](https://koobas.hobune.stream/wayback/20220611230037im_/https://answers.unity.com/themes/thub/images/avi.jpg)