Search Unity

How to trigger a button as soon as it's tapped/pressed instead of on release?

Discussion in 'UGUI & TextMesh Pro' started by roseportalgames, Jan 14, 2019.

  1. roseportalgames

    roseportalgames

    Joined:
    Aug 9, 2017
    Posts:
    173
    OnClick only triggers if a button is pressed and released with the cursor (or finger) still over the button. To avoid this buggy looking situation, I'd like to trigger the button as soon as it's pressed/tapped. How can I achieve this?

    OnMouseDown does not work.

    Thanks. :)
     
  2. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,096
    Add an
    Event Trigger
    to your button object and add the event type
    Pointer Down
    there.
    You may exchange the
    Button
    Component with a
    Selectable
    Component since you do not need the callback of the button anymore.
     
    GoxYaZK likes this.
  3. MarkoGisG

    MarkoGisG

    Joined:
    Jan 22, 2023
    Posts:
    1
    Thanks bro that helped a lot!