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.
How to do it...
To begin, we can create a panel by right-clicking on the Hierarchy panel. Then click on UI | Panel and rename it to CoinPanel. We should also resize it in order to see the entire panel on the screen.
Next, we need to create a script for...