Search Unity

Perform Action only if click not above UI-Element

Discussion in 'UGUI & TextMesh Pro' started by ClaasM, Dec 17, 2014.

  1. ClaasM

    ClaasM

    Joined:
    Oct 4, 2014
    Posts:
    26
    Hey Community,

    How can i check if a click (or a touch) is above an UI-Element and only do something if it's not?
    I thought this would be easy but after I tried Raycasting with the UI-Layer blocked and Canvas Groups I still didn't find a solution.
    My Problem is that an action has to be performed unless the player is clicking e.g. a button, and currently I dont have any idea on how to do that (also there isnt much information about that and the new UI system on the internet yet so I have to ask such a simple question).

    Thanks,
    Claas M.
     
  2. brendan-vance

    brendan-vance

    Joined:
    Jan 16, 2014
    Posts:
    36
  3. ClaasM

    ClaasM

    Joined:
    Oct 4, 2014
    Posts:
    26
    Still returns true when the pointer is over a UI Element
     
  4. Sebioff

    Sebioff

    Joined:
    Dec 22, 2013
    Posts:
    218
    Do you want to do something only if the mouse is anywhere but one specific UI element, or do you want to do something if it is not over any UI element? The question can be understood both ways.
     
    ClaasM likes this.
  5. ibyte

    ibyte

    Joined:
    Aug 14, 2009
    Posts:
    1,048
    ClaasM, I was told EventSystem.IsPointerOverGameObject should really have been called EventSystem.IsPointerOverUIObject

    In the documentation it says "Is the pointer with the given id over an EventSystem object?" In your case you want to use

    if (EventSystem.IsPointerOverGameObject =! true)

    Please be aware that if you have a panel that is stretched over the entire screen of your device it will always return true.

    http://forum.unity3d.com/threads/ugui-and-input-handling.286223/

    iByte
     
    ClaasM likes this.
  6. ClaasM

    ClaasM

    Joined:
    Oct 4, 2014
    Posts:
    26
    Thanks iByte, that solved it!
    (Also i meant over any UI-Object)

    Claas M
     
    brendan-vance likes this.