Making a draggable panel

In same cases, UI elements require some kind of interaction with the player, and the next three recipes will teach you how to create interactive panels. In this recipe, you will learn how to make a panel draggable. For instance, the player will be able to move the panel all around the screen by dragging it. This is useful when we want to allow the player to organize his UI with his logic and order. In order to do this, we will use the Event Trigger (Script) component and develop a script to handle the interaction.

How to do it...

  1. To begin, we can create a panel by right-clicking on the Hierarchy panel and then on UI | Panel. We should also resize it so that we can see the entire panel on the screen.
  2. Now we need to create ...

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.