- Home /
Unity UI: neglect transparent area of button and trigger user input underneath it.
Hello everyone,
The picture itself explains my issue. So I have many shapes (puzzple pieces), please check pic2 attached.
So whatever the user sees and taps to drag, must be dragged.
I am using (IBeginDragHandler, IDragHandler, IEndDragHandler). After some research, I saw methods of ignoring raycast on transparent areas .. etc .. but since I am not using raycasting here, what suggestions do you have?
@Fattie , @robertbu ,@aldonaletto would like to hear your point of view.
It might be possible with a (hacky) workaround.
If you check if the cursor is inside the two buttons spaces (via Input.mousePosition and the UI elements' RectTransform component), and then also use GetPixel to check the pixel color of the green button's image to see if it's alpha value is 0, you should be able to do what you are ltrying to do :) Just in theory, of course.
Answer by loliconest · Jun 07, 2017 at 01:41 PM
You can look into UI.Image-alphaHitTestMinimumThreshold
it works, but i'm using SetPixels for the button image (to remove the alpha), after applying and doing alphaHitTest$$anonymous$$inimum, the position of my button changes and goes to wrong position, the image position is right, the button is wrong
Answer by Xarbrough · Nov 10, 2016 at 05:03 PM
This is not yet possible with the builtin UI components. They might add some kind of user defined raycast area or use graphic masks for this, but right now, it simply is not supported.
Do you require those images to be buttons? You could simply make them sprites with a polygon collider or any shape which matches well enough and use the IPointerClickHandler etc to build your click actions. Is that something you can try?
Yeah, I agree. There are these "elephant in the house" things with unity that have yet to be implemented..