RectTransform and it's bounds

Hi, I’ve created a simple canvas with image inside. Image is an attack, which player can drag and drop on screen (my game is 2d). So I’ve just added BeginDrag, OnDrag and EndDrag events and moving special sprite with it, which represents attack range area. However I want to left user possibility to cancel his attack. So if he’d drop attack on image on canvas it should not fire. And I’m struggling how to calculate this. I only found a function, which can convert mouse position to rect transform coordinates:

RectTransformUtility.ScreenPointToLocalPointInRectangle (rect, screenPoint, Camera.main, out localPoint);

However how to check if this “localPoint” is in rect transform bounds?

You can implement OnEndDrag(PointerEventData eventData) on your draggable item. Inside there you can check if eventData.pointerEnter is null (which means they dragged outside of UI) or if it is not null, you can do other checks to determine the outcome of the drag (eventData.pointerEnter is a gameobject so all the normal stuff like tag or GetComponent).

Hi, thanks for an answer. I just did just like you said, but pointerEnter is always not null in my case. However, I’ve just added Pointer Enter and Pointer Exit events, so I just have bool which remembers if pointer is inside or outside. And it works, thanks for clues.