Sitemap
Nerd For Tech

NFT is an Educational Media House. Our mission is to bring the invaluable knowledge and experiences of experts from all over the world to the novice. To know more about us, visit https://www.nerdfortech.org/.

Member-only story

How to Unity

Drag And Drop UI Objects in Unity

Use IDragHandler and IDropHandler to implement a drag-and-drop feature in Unity.

4 min readJun 12, 2024

--

As seen in this previous article, some interfaces can be implemented by a MonoBehaviour script in Unity to have pointer-related interaction involving UI elements.

In this article, I will show a couple more, about the well-known drag-and-drop feature. Namely, I will focus on:

which you can explore better in the Official Scripting API manual. Each interface exposes a method, respectively:

OnEndDrag(PointerEventData pointerEventData)
OnBeginDrag(PointerEventData pointerEventData)
OnDrag(PointerEventData pointerEventData)
OnDrop(PointerEventData pointerEventData)

Quite straightforward: what happens when the drag operation ends, begins, is being performed, and what happens when what’s been dragged is dropped.

Let’s look at a use case: dragging items around and dropping them into slots.

--

--

Nerd For Tech
Nerd For Tech

Published in Nerd For Tech

NFT is an Educational Media House. Our mission is to bring the invaluable knowledge and experiences of experts from all over the world to the novice. To know more about us, visit https://www.nerdfortech.org/.

Daniele Quero, PhD
Daniele Quero, PhD

Written by Daniele Quero, PhD

A professional developer with passion for game developing and skill-growing. A former Nuclear Physics Researcher who changed his life to pursue his dreams

No responses yet