Why isn't there a simple way to check, if the pointer is over any ui object?
I wonder why there isn't a method like "IsPointerOverUI" somewhere in unity. Maybe as a public method of Canvas or at any other available location. It seems that there is no satisfying solution to get this information ... or I'm unable to find it. And I don't talk about adding custom scripts to each UI element to set a flag when the pointer is over that element or something like that. That all is too elaborate.
Please let me now if I'm wrong and there is a easy way or give us this function in the next release!
Thanks in advance for all your answers
Peter
Answer by Pratap-Dafedar · Feb 25, 2016 at 07:41 AM
Try this one. EventSystems.EventSystem.IsPointerOverGameObject
But, you might have see this will not work on non-event UI elements. like simple image or text components. To make it work in any UI element -
Add a Button with empty action.
Transition = None.
And that's it.
now it works with any UI element.
Answer by chiragms · Feb 02, 2021 at 05:12 AM
@Pratap-Dafedar You are a genius! This is the exact answer I was looking for. I've been banging my head against the wall because of this problem. Some UI elements worked with isPointerOverGameObject and some didn't and I couldn't figure out why but you my friend answered it for me.
Thanks bro.
Your answer
Follow this Question
Related Questions
Unity UI create and drag with one click 0 Answers
How to create an if statement for each element within a list C# 2 Answers
Unity 5.1 GUI mask disappears in Android build 0 Answers
Adjusting content display. 0 Answers
Unity Dropdown Menu Not Closing 1 Answer