- Home /
Question by
octavioroar · Nov 16, 2019 at 01:14 AM ·
uimobilejoystickeventsystemmobile devices
EventSystem.IsPointerOverGameObject doesn't work on virtual joystick (mobile)
Greetings,
Sorry beforehand if the question itself is dumb, but I can't seem to find an answer.
As you can see, my code was meant for multitouch and it works perfectly with UI buttons, no problem there, but when I'm using virtual joystick ("Joystick Pack" by Fenerax Studios in the asset store) it only works partially (which is obviously not good), my finger sometimes interacts with the background anyway, even if I'm clearly inside the boundaries of the UI.
I already tried disabling its raycasts as suggested for regular UI buttons, but it doesn't work, it just disables its functionality entirely. I'm using Unity 2019.2 and Joystick Pack 2.1, if that helps. Thanks!
void Update()
{
if (Input.touchCount > 0)
{
foreach (Touch touch in Input.touches)
{
if (touch.phase == TouchPhase.Began)
{
if (IsPointerOverGameObject(touch.fingerId))
{
Debug.Log("Hit UI, Ignore Touch");
}
else
{
Debug.Log("Handle Touch");
}
}
}
}
}
bool IsPointerOverGameObject(int fingerId)
{
EventSystem eventSystem = EventSystem.current;
return (eventSystem.IsPointerOverGameObject(fingerId) && eventSystem.currentSelectedGameObject != null);
}
Comment