- Home /
eventSystem.IsPointerOverGameObject for mobile devices
I have the following code to prevent a raycast from being cast into the 3d world when my mouse is on a uGUI element.
if (!GUIController.Instance.eventSystem.IsPointerOverGameObject())
{
//raycast here on mouse click
}
Works perfectly for editor, but when I build for iOS, it doesn't work. Does anyone has a solution for this? Thanks
Answer by fafase · Jun 17, 2015 at 10:49 AM
private int fingerID = -1;
private void Awake(){
#if !UNITY_EDITOR
fingerID = 0;
#endif
}
// Elsewhere
if (!GUIController.Instance.eventSystem.IsPointerOverGameObject(fingerID))
{
//raycast here on mouse click
}
The method gets a default value of -1 when none is passed, and that default value is not the same as the one needed for mobile, 0.
With this code, you have nothing to do when you pass from editor to mobile thanks to the macro (if you need standalones then you need to add them).
At least I had the same issue with another similar method (IsPointerOverGameObject) and that fixed it.
Thanks for the quick answer, Fafase. I'll let you know how it worked in the next iOS build.
$$anonymous$$aybe something has changed in the API. Try the example from the documentation:
https://docs.unity3d.com/ScriptReference/EventSystems.EventSystem.IsPointerOverGameObject.html