I want to make buttons for a mobile build, testing with android 11. To set variables, which I read in other scripts, I use the following code:
foreach (Touch touch in Touch.activeTouches)
{
Vector2 pos = touch.screenPosition;
if (player.leftRect.Contains(pos))
input = -1f;
if (player.rightRect.Contains(pos))
input = 1f;
if (player.jumpRect.Contains(pos))
{
jumpHeld = true;
if (touch.phase == TouchPhase.Began)
jumpPressed = true;
}
if (player.dashRect.Contains(pos) && touch.phase == TouchPhase.Began)
dashPressed = true;
}
With the rects being set from rectTransforms in Start(). This snippet gets called in Update. However, when on the build, every press is delayed 200-300ms.
I tried using the new InputSystem Unity provides, however that only increased the latency to around 500ms.
Lots of other games run smoothly on this phone, so are there any fixes or best practices one should do?
activeTouches, but that wouldn't account for 200-500ms. It's likely you have some latency introduced in the code that acts on this, or your game is overwhelming the phone's processing and the update ticks are falling behind realtime. \$\endgroup\$