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

Question Detect GetTouch or GetMouse on an UI Element

Discussion in 'UI Toolkit' started by QuilloGames, Dec 14, 2022.

  1. QuilloGames

    QuilloGames

    Joined:
    Jul 31, 2017
    Posts:
    17
    Hi, I am catching the GetTouch or GetMouse event and trying to check whether it happens on certain UI Elements.

    The "clicked" method doesn't work because it needs also the MouseUp event.
    I have tried working around using UIElement.clickable.lastMousePosition but the lastMousePosition would not change until I click the UI Element again. So even if there are clicks on other places after clicking the UI Element, the code stills think I am clicking on the UI Element.

    This sounds like a simple task but I couldn't find the appropriate methods.

    Thank you for any ideas.
     
  2. antoine-unity

    antoine-unity

    Unity Technologies

    Joined:
    Sep 10, 2015
    Posts:
    733
  3. QuilloGames

    QuilloGames

    Joined:
    Jul 31, 2017
    Posts:
    17
    Thanks! It works! For others who come across this post in the future, I followed the example in this page https://docs.unity3d.com/Manual/UIE-Pointer-Events.html but instead of evt.target I used evt.currentTarget so that the registered object can be identified even when the Pointer is on some child element of he registered object.