Hello Guest

Author Topic: Check mouse click if on UI or not  (Read 3815 times)

xikky

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 20
    • View Profile
Check mouse click if on UI or not
« on: September 03, 2014, 07:49:21 pm »
I know this can be worked out using Physics.Raycast, but is there any other way? and is Physics.Raycast expensive in performance?

Thank you!

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Check mouse click if on UI or not
« Reply #1 on: September 04, 2014, 09:45:34 am »
One raycast is fine, especially if you've put all your UI in layers. We could provide this information but due to how stuff works in Unity, theres no way to guarantee our update has run before your function call.

xikky

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Check mouse click if on UI or not
« Reply #2 on: September 04, 2014, 01:04:46 pm »
I think I'm not understanding something here :/ .. I thought i could work with ignoring the UI layer but the trouble is that when clicking on a UI element, it's layer is not picked, but the raycast picks layers from behind the UI element.

Can someone provide how I can work around this? thankyou!

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Check mouse click if on UI or not
« Reply #3 on: September 05, 2014, 10:09:11 am »
No I don't think you can ignore the UI layer. What I mean is if you have all your stuff in a UI layer, you can issue 1 cheap raycast to the UI layer only to see if you've clicked on something and the hit point. You can then decide whether or not to issue your raycast to do whatever you need.