- Home /
How to click on irregular buttons in new ui
Hi
i have some very irregular button forms that are overlapping with there bounding boxes. So clicking on them is not working as expected (because of overlapping areas).
Perfect would be if i have a way to say "test alpha" for raycast or create better pixel perfect colliders. But i have no idea what the ideal/preferred way would be
Greetings Thomas
Answer by allenallenallen · Aug 11, 2015 at 09:17 AM
Polygon Collider 2D
http://docs.unity3d.com/Manual/class-PolygonCollider2D.html
And there's this:
http://forum.unity3d.com/threads/none-rectangle-shaped-button.263684/#post-1744521
Answer by NeverHopeless · Aug 11, 2015 at 09:27 AM
I also faced this situation when i have angular button. I Solved it by using PolygonCollider2D component, but the problem is, still there were overlapping areas in the angular buttons. To fix this I edited polygon collider component from inspector. There is also a possibility to detect which buttons were touched using Physics2D.OverlapAreaAll
and find the most appropriate one based on criteria. But i personally feel its too hard to go with it if you can easily edit the collider component, since it is one time effort so it will not cost for performance each time as in the other case i discussed.
Hope it helps!
Answer by TandT · Aug 14, 2015 at 11:21 AM
Hi i now found the AlphaRaycaster it does exactly what i need and is already existing code. Well worth the money :-) https://www.assetstore.unity3d.com/en/#!/content/28601
Answer by dnwsaa58 · May 28, 2019 at 02:50 PM
If your button relies on an image to detect the click (with the RaycastTarget
option checked), you can adjust the value of a threshold which specifies the minimum alpha a pixel must have for the event to considered a "hit" on the Image. See the documentation : Image.alphaHitTestMinimumThreshold
Your answer
Follow this Question
Related Questions
Holding down UI Button and shooting raycast from touch position doesn't work simultaneously:(( 0 Answers
Raycasting UI components 3 Answers
UI button and raycast script that I have made both aren't working to change my scene 1 Answer
Unity 5 new UI Button Colliders moved to the left in different resolutions 1 Answer
Detect only UI button click 3 Answers