Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

PointerClick vs Drag

Discussion in 'UGUI & TextMesh Pro' started by benjyblack, Sep 25, 2014.

  1. benjyblack

    benjyblack

    Joined:
    May 13, 2013
    Posts:
    3
    I'm trying to trigger a callback on a Click event. I understood a "Click" to be a MouseDown + MouseUp in the same position but this doesn't seem to be the case in Unity 4.6. I can click, drag the mouse around, let go, and it will still trigger the PointerClick event. Is this a bug or is it the intended behaviour? Any idea how to get around this?

    Thanks!
     
  2. phil-Unity

    phil-Unity

    Unity UI Lead Developer Unity Technologies

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    Are you releasing the mouse over the down object? we check if the down object is the same as the up object
     
  3. benjyblack

    benjyblack

    Joined:
    May 13, 2013
    Posts:
    3
    Yes, I am releasing the mouse over the same object. I guess that behaviour makes sense actually.

    Regardless, I've managed to get around it in my code. For anyone wondering how, I just store the mouse position on a PointerDown event and then compare that position to the current mouse position on the PointerUp event. If they match, then it's a "Click".
     
  4. phil-Unity

    phil-Unity

    Unity UI Lead Developer Unity Technologies

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    Yea thats the behaviour we want. Be careful with checking the position the chances the mouse or finger touch moves slightly is very high which could cause you to not send a click
     
  5. benjyblack

    benjyblack

    Joined:
    May 13, 2013
    Posts:
    3
    Great, thanks for the tips Phil