Unity UI Button: OnClick: Pass Click Position[SOLVED]

Hi, I am building for mobile, so when my player clicks a button, if I need to know the finger position (which is no longer on screen, as it was a released tap), is there a Unity UI feature that allows for specific information, like tap pos to be gathered via the UI button?

I can just monitor in update, but I was hoping an embedded solution.

Thank you.

You can make use of OnPointerUp.

thanks.
At the moment, I am using this solution…

    void Start () {
         ui_btn_move.onClick.AddListener(() => OnClickAction(Input.mousePosition));


    }
    void OnClickAction (Vector2 mousePos){
        print ("ON CLICK: mouse pos: " + mousePos);
        moveTo (mousePos);
    }

Ah, You caught that!

I had removed that post because it doesn’t handle edge cases very well. To support multiple fingers at the same time, you would need to track the fingers. If you’re tracking the fingers, you might as well just check which ones were near the button and get the data that way…

With OnPointerUp you get much more reliable (and detailed) data. But if it works, it works!

1 Like