0
\$\begingroup\$

In Canvas, I drag some UI objects to a panel using this code:

public void OnDrag(PointerEventData eventData)
{
   Vector3 screenPoint = Input.mousePosition;
   screenPoint.z = 10.0f;
   Item2Drag.position = Camera.main.ScreenToWorldPoint(screenPoint);
}

But what I can't figure out is when I dropped an object on the panel, how can I get the gameObject which has been dropped?

\$\endgroup\$
1
\$\begingroup\$

I figured it out.

I can get it by eventData.pointerDrag from OnDrop function.

public void OnDrop(PointerEventData eventData)
{
   GameObject droppedObject = eventData.pointerDrag;
}
| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.