Hello, I’ve started using the new UI system since everyone says it’s better than the old (GUI system) but I can’t find anywhere how to check if the mouse is over a specific UI element for example. Currently I’m using if (EventSystem.current.IsPointerOverGameObject ())
which works fine on detecting if the mouse is over any UI element but I want to limit that to a specific UI element ether by using tags or game object or something without placing the script on the UI itself because i will have many UI elements and i don’t want to have a script for each element. I’m trying to achieve something very specific so the easy way from the inspector is not helping me out here.
I think you can simply do the following :
if (EventSystem.current.IsPointerOverGameObject () &&
EventSystem.current.currentSelectedGameObject != null &&
EventSystem.current.currentSelectedGameObject.CompareTag( "yourTag" ) )
{
// Do something
}
You could use event triggers:
https://docs.unity3d.com/ScriptReference/EventSystems.EventTrigger.html