Question by
Quantum44 · Sep 21, 2020 at 10:10 PM ·
user interfaceevent triggeringmouseover
Help with Detection of Mouse Over Irregular UI Elements
Currently I am using event triggers within the inspector to control UI colour changes as the mouse hovers over elements as per this code, which works fine.
public void MouseEnter()
{
Image selectorImage = gameObject.GetComponent<Image>();
LeanTween.value(gameObject, Color.white, Color.grey, 0.3f).setOnUpdate((Color val) => {
selectorImage.color = val;
});
}
public void MouseExit()
{
Image selectorImage = gameObject.GetComponent<Image>();
LeanTween.value(gameObject, Color.grey, Color.white, 0.3f).setOnUpdate((Color val) => {
selectorImage.color = val;
});
}
My main issue is that my UI elements are packed tightly together and have polygonal shapes, leading to overlapping gameobjects and a very buggy feeling when moving the mouse over the elements. I tried using a polygon collider 2D on each of the elements, however it seems that the event triggers use the actual bounds of the gameobject, which are rectangular. It is also problematic that the functions OnMouseEnter() and OnMouseExit() only work for non-UI elements. Does anyone have any workaround for this issue?
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613012259im_/https://answers.unity.com/themes/thub/images/avi.jpg)