- Home /
UI works in editor, but not on mobile device
Hi! I've got an UI panel in front of a plane. There is a button in this panel. There is a script which hides the panel on click/touch (OnMouseDown function) attached to the plane. So, clicking anywhere except the button should close the panel. Everything works fine in the editor, but on mobile the panel gets closed even when the user touches the button, so it's almost impossible to click it (for some reason, if you click the button really fast just after the panel appears, everything works well). I'm not sure if it's a Unity bug or maybe I just don't know how the touch handling in Unity works. Could you guys help me? Thanks in advance.
Answer by Vicarian · Oct 13, 2018 at 06:14 PM
Try using EventTriggers instead. I know for certain they're compatible with CrossPlatformInput. So, add an EventTrigger to the panel. Click Add Event Type and choose OnPointerClick, then click the + icon that appears. Drag the panel from the scene into the field that shows up, and choose GameObject > SetActive(bool) from the dropdown menu. Make sure the check box that appears is unchecked. Remove the OnMouseDown message from the script on the panel as it's no longer needed. Test it out.
@Vicarian Thanks mate, everything works well now, Could you post it as an answer so I could accept it ;)?
Awesome! its working like a charm. But do you know why its not working with simple onClick() events?