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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.