Author Topic: How do I detect when multiple NGUI crosshairs overlay multiple 3D game objects?  (Read 1963 times)

yohann

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 15
    • View Profile
I have an NGUI UI with a 3 x 3 grid of crosshairs that overlays a first person view. That all works great, but now I need to be able to do/show stuff when each of those 9 crosshairs overlays an object in the 3D world.

Maybe put simpler, how do I detect when an NGUI element is over a 3D gameobject, and then get info about that 3D object?

I'm usually pretty good at figuring stuff out, but I'm at a loss here of where to even start. Any ideas or direction is greatly appreciated!!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Edit: I misunderstood the question the first time. To detect when an NGUI widget is over a 3D object, you need to do your own Physics.Raycast into the screen. To determine the widget's position in screen space, get the transform.position and convert it to screen space via Camera.WorldToScreen (check Unity's docs).