My mouse on two overlapping GameObjects

Hello,

I would like to know how to get the full information when my mouse is on two overlapping Image GameObjects in an unique 2D Canvas, as “OnPointerEnter” won’t work for both.

For example, with these blue and green round images, i would like a script that aknowledge when the mouse is in the red zone (aka “also in the blue image zone”) :

195510-mouse-two-gameobjects.png

Thanks !

You can use OnPointerEnter and OnPointerExit to know when it enters and exits each circle, just store a bool isMouseInside;

Then some other script would test

if (circleA.IsMouseInside()) && circleB.IsMouseInside()) { 
    // Do something
}

Alternatively you can manually fire the raycast yourself every frame and test if both are hit.

        PointerEventData pe = new PointerEventData(EventSystem.current);
        pe.position =  Input.mousePosition;
        List<RaycastResult> hits = new List<RaycastResult>();
        EventSystem.current.RaycastAll( pe, hits );