Making a drag-and-drop item system in unity

Mario lopez
Sep 14, 2023

--

Okay so in this challenge we will want to pick up a Ui image when we click on it and when we hold the mouse button and move the mouse the image will move with it and when we let go the image will drop on that spot.\

The first thing we need is 3 images then make a new script.

In this script we need to get the event system library this will allow us to set a IHandler this what we need to drag and drop.

Where it said MonoBehaviour you can add IDragHandler, IEndDragHandler then implement interface on both.

Then in OnDrag put transform will equal to the event data position and then do the same thing in OnEndDrag.

Now add this script into your Images then test.

See you next time.

--

--