How do I detect when one UI Image is over another?

Hi all! Sure this is a pretty simple thing but it’s giving me a lot of trouble. My game has a hand UI Image on a UI panel along with two button Images. The player drags the hand over which button they want to press, and then hits space bar to actually hit the button with the hand.

I have the dragging part working fine, but I cannot for the life of me figure out how to detect what button the hand is over. I have read a lot about the Graphic Raycaster component, and I’m pretty sure that’s what I want, but I can’t figure out how to cast that from another UI element; every tutorial I find is about sending the ray from your mouse pointer, which I don’t want.

Can anyone lend a hand?

Hi,

rectTransform has lots of stuff, just check the API page… for example you could try its rect, rect has Contains and Ovelaps commands IIRC.

1 Like

Perfect, thank you. The Overlaps function in rect was perfect for my needs.

This was a godsend thank you

Please us the Like button to show your appreciation rather than necro old threads.

I’ll also move this thread to the UI forums where it belongs.

Thanks.