UI in Unity: Snapping to Slots

Zac Bogner
Mar 17, 2024

Recently, I created a draggable UI interface.

This article, will focus on snapping the images to slots.

We create two new images as our drop item backgrounds, and add a Drop Item script to both objects.

Inside the Drop Item class, we will get reference to the IDropHandler interface, and set the dropData variable to equal the position of the pointer location to the current position.

Next, we will want to turn off the Raycast target Boolean value on the image we drag to the item slot to drop inside the Drag Item class.

And now, we have a simple drag and drop user interface to build upon, allowing to snap to position where we end our drag item interface.

Next, we will wrap up the Event System Interface topic with creating a mini-game — Dropping the Correct Item to Slot.

--

--

Zac Bogner

Game Designer and Level Designer, formerly with Rainbow Studios. Focused in Unreal Engine with experience in Unity. Former Race Car Driver.