Search Unity

Question Detecting button press (not click) from code

Discussion in 'Animation' started by MangoMan121, Apr 12, 2021.

  1. MangoMan121

    MangoMan121

    Joined:
    Aug 6, 2019
    Posts:
    1
    Essentially, I'm working for mobile (touchscreen) and want to use DoTween for the UI animations.

    The issue is while I can detect OnClick(), I want to animate when eg a button has been pressed (finger has touched screen but not yet left) - so they can tell something has happened before they release their finger.

    But I can't for the life of me find a way to do this! I've tried seeing if I can access the button trigger that is sent to the animator, and various other ideas but all to no avail. Would love some help!
     
  2. launzone

    launzone

    Joined:
    Dec 2, 2015
    Posts:
    57
    not sure if it works exactly like that with touch but GetMouseButtonDown triggers in the moment you click/ push down. i didn't develop for mobile in a long time but it could be that depending on the platform mouse button functions just work for touch too.
    if you want to control it with the button i think its OnPointerDown, but check out the docs for buttons.