A very interesting feature that we will add to our game is the possibility for the players to choose where their in-game UI elements are displayed. This ensures a much greater flexibility of the user interface.
The player can simply touch and hold their finger on any in-game UI element, and the game pauses and the touched element becomes draggable. The game resumes as soon as the player has dropped its UI element at their required location.
We will use the UIDrag Object
component along with Box Colliders
to make our UI elements draggable. These colliders will be attached to the widgets' sprites so that their Collider auto-adjust to match option becomes available.
First, we have to add box colliders on our UI elements:
Select our InGame3DUI | Score | Background GameObject:
In the Inspector panel, click on the Add Component button.
Type
box
to search for components with that name.Select Box Collider and hit your keyboard's Enter key.
Select both InGame3DUI | Score...