In this recipe, you will learn how to make a floating UI element. This is a nice effect to use within every kind of user interface. If you are going to use a very slow movement with a small amplitude, you can use this effect even on menus to give them more life and a professional look. A floating element can add yet another type of dynamic element to the UI, ultimately breaking the usually rigid nature that UI elements tend to have.
First of all, we need to create an UI element. In this example, we will create a panel that can be the background of a menu. To do this, right-click on the Hierarchy panel and then navigate to UI | Panel. Finally, rename it Floating Panel. Of course, it is possible to resize and place the panel as we wish.
Next, we need a script that moves our panel on the screen in such a way that it seems to float. Thus, navigate to Add Component | New Script and name it FloatingUIScript. Then, click on Create and Add.
Now, double-click...