1

I am trying to create an game board by using Unity and NGUI and everything is working ok now. I am using the DragNDrop script on my dragable object and on my fields on the board I am using UIDragDropContainer. But, is there a way I can tell my dragable object which field the object is over or attaching it self to?

I have scouted the net, but have not found an solution.

Any help is appreciated :-)

Mansa
  • 2,277
  • 10
  • 37
  • 67

2 Answers2

0

Use the UICamera.hoveredObject to get the last gameObject (with a collider) that the mouse or touch was last over.

Dover8
  • 607
  • 3
  • 17
0

In one of my projects I came across a same issue. What I did was inherit the NGUI's UIDragDropItem script and created a delegate to tell me about the object. I have also added the source:

public class Custom_DragDropItem : UIDragDropItem {

    public delegate void DragDropDelegate(GameObject TargetObject);

    public DragDropDelegate onDragDrop;
}

All you have to do is use this script instead of UIDragDropItem on your draggable items in the inspector and register to the delegate onDragDrop and it will pass you the target object on which the item is dropped.

Anas iqbal
  • 1,036
  • 8
  • 23