Creating a drag-and-drop element

Often, UI elements require some kind of interaction with the player. This recipe, along with what we have done in the previous two recipes, will teach you how to create interactive panels. In particular, you will learn how to create two panels: one from which we can drag an element (such as a coin or an item) and one on which we can then place it. This is useful when we are developing a system wherein we need to drag objects from one place to another. For instance, it's common to find this system in a shop menu, where the player can decide what to buy and drag what he wants into his inventory. In order to do this, we will use the Event Trigger (Script) component and develop a script to handle the interactions. ...

Get Unity UI Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.