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

How can I detect the mouseEvent is over UIElement or gameobject?

Discussion in 'UI Toolkit' started by whiteclouds2016, Oct 29, 2020.

  1. whiteclouds2016

    whiteclouds2016

    Joined:
    Sep 22, 2017
    Posts:
    18
    I need to distinguish between the two. Because my character will be action when I click the mouse.
    I found it is not working well with "EventSystem.current.IsPointerOverGameObject" what I always been used in UGUI.
    So, I need a judge logic when I click the UI or gameObject. Avoid it will execute twice in UI logic and gameObject logic.
    Have any suggestion for me : )
     
  2. SteveJ

    SteveJ

    Joined:
    Mar 26, 2010
    Posts:
    3,066
    The UIElementPointerEnter & UIElementPointerExit events might help you.
     
  3. whiteclouds2016

    whiteclouds2016

    Joined:
    Sep 22, 2017
    Posts:
    18
    I guess your idea is make a flag when mouse enter UIElement. And judge this flag is over UI or gameObject:)
    Thanks, I will try to it
     
  4. whiteclouds2016

    whiteclouds2016

    Joined:
    Sep 22, 2017
    Posts:
    18
    It is something wrong when I move mouse enter the UI and hover it.
    It will execute PointerEnterEvent and PointerOutEvent right now even if my mouse still hold in the UI.
    Is my fault?

    code:
    upload_2020-10-29_15-42-28.png

    print:

    upload_2020-10-29_15-41-51.png