Author Topic: How do I check if mouse is over UI?  (Read 3434 times)

storm33229

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 44
    • View Profile
How do I check if mouse is over UI?
« on: May 29, 2013, 07:56:32 PM »
How do I determine that the mouse is over the UI? I don't want clicks to process in the game if I am busy clicking on the UI (even if the UI I click isn't responding to clicks, or doesn't have a collider).

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How do I check if mouse is over UI?
« Reply #1 on: May 30, 2013, 12:29:14 AM »
UICamera.hoveredObject != null.

NGUI events works with colliders, not widgets. If there is no collider then the widget will not receive any events, and hoveredObject will not be updated.

storm33229

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 44
    • View Profile
Re: How do I check if mouse is over UI?
« Reply #2 on: May 30, 2013, 08:36:46 AM »
UICamera.hoveredObject != null.

NGUI events works with colliders, not widgets. If there is no collider then the widget will not receive any events, and hoveredObject will not be updated.

That works. I just had to write a script to auto-attach (and correctly size) a collider to a widget on Start(). It does this for all widgets. I do not have a very intense UI though.