Author Topic: OnDrag trigger order  (Read 2189 times)

superp

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
OnDrag trigger order
« on: July 22, 2014, 12:19:40 AM »
Hi,
I have Main Camera that has BoxCollider 2d. I am using it to receive OnDrag() and move the screen when cursor is dragged around the screen.
It works reasonably well until i want to receive OnPress event on other objects in the screen.
Basically the camera's collider is eating all events.
How do i order objects so that if click on an object, it receives OnPressed while if clicked on no object, the camera receive the event?


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: OnDrag trigger order
« Reply #1 on: July 22, 2014, 08:50:32 PM »
Events arrive on widgets that have the highest depth. You need to make sure that all colliders are on widgets, not empty game objects -- and the widget's depth is what will determine which one will get it. If you need an invisible widget, ALT+SHIFT+W.

superp

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
Re: OnDrag trigger order
« Reply #2 on: July 23, 2014, 12:37:54 AM »
thanks. i am not entirely surely how i can do "need to make sure that all colliders are on widgets, not empty game objects"
Here is my set-up. I have Main Camera displaying normal Unity game objects like tanks and blocks.
This is the camera that i want to be moved within the fixed world when mouse is dragged.
Today, I attached a script to this camera object that handles OnPress() and it is eating all messages even the ones that should go to other objects because I have collider that fits the camera's view.

Then I have UI Root and NGUI camera that shows UI like home buttons and status and they do not move.

How would I do this? Thanks

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: OnDrag trigger order
« Reply #3 on: July 23, 2014, 07:29:32 PM »
Camera won't receive any events. Only colliders can receive events. When dealing with a UI system, NGUI does a raycast to see what colliders are hit. Those colliders are then sorted by the depth of the widget component attached to those colliders. When you put a collider on a non-widget, it will effectively use the depth of the top-most widget. So for example if you have this:

UIRoot
- UICamera (collider)
-- Widget (depth 1)
-- Widget (depth 2)
-- Widget (depth 3)

...the collider will have effective 'depth' of 3. This is why I say -- put colliders on widgets, not plain game objects.