Search Unity

Custom shape for clickable area/button?

Discussion in 'UI Toolkit' started by Wisearn, Nov 19, 2020.

  1. Wisearn

    Wisearn

    Joined:
    Jul 10, 2012
    Posts:
    8
    Hey people, loving the new toolkit.

    Is there a way to have a button with an onclick event that isn't a rect?

    Say I have a circle for a button and I don't want interaction to cover the entire bounding box, or a hexagon pattern where I don't want rows to block interaction between each row at the overlap.

    Thanks in advance,
     
  2. griendeau_unity

    griendeau_unity

    Unity Technologies

    Joined:
    Aug 25, 2020
    Posts:
    248
    The only way to do that right now would probably be to create a custom class inheriting from Button, and override the ContainsPoint() method.

    Code (CSharp):
    1.  
    2.     public class CustomShapeButton : Button
    3.     {
    4.         public override bool ContainsPoint(Vector2 localPoint)
    5.         {
    6.             return ** custom implementation here **;
    7.         }
    8.     }
    9.  
     
    Last edited: Nov 23, 2020