Hi,
I’ve been using Touchscreen to simulte player inputs recently. And I have encountered this for several days. My code is like this:
Touchscreen device = InputSystem.AddDevice<Touchscreen>(deviceName);
...
void TestClick()
{
InputSystem.QueueStateEvent(device, new TouchState
{
touchId = touchId,
phase = UnityEngine.InputSystem.TouchPhase.Began,
position = pos,
isPrimaryTouch = true,
});
InputSystem.QueueStateEvent(device, new TouchState
{
isTap = true,
touchId = touchId++,
phase = UnityEngine.InputSystem.TouchPhase.Ended,
position = pos,
});
}
Then when i call TestClick() the firt time, the click event works right. The gameobject responds the click. Everything is right. But later (i.e. 1 second later) no matter how many times I call TestClick(), it doesn’t work.
After working into this for days, I find that if I change the code like this:
void TestClick()
{
InputSystem.RemoveDevice(device);
device = InputSystem.AddDevice<Touchscreen>(deviceName);
InputSystem.QueueStateEvent(device, new TouchState
{
touchId = touchId,
phase = UnityEngine.InputSystem.TouchPhase.Began,
position = pos,
isPrimaryTouch = true,
});
InputSystem.QueueStateEvent(device, new TouchState
{
isTap = true,
touchId = touchId++,
phase = UnityEngine.InputSystem.TouchPhase.Ended,
position = pos,
});
}
Every time when I call TestClick(), I remove the device and then add it. The click works all the time.
I can’t tell why this happen, even if I read all the api documents about Touchscreen, TouchState etc.
Thanks for helping.