Creating a menu with an idle animation

The previous recipes taught you how to make a menu appear or create a transition that allows the menu to enter the screen. We are now going to see how to make an idle animation, where the object just cycles through a general animation, such as hovering or pulsing. To do this, we need to create an animation that can be played as a loop. In this recipe, we will see how to change the color background of the pause menu that we created in the first recipe, Appearing and disappearing menu.

How to do it...

  1. First of all, we need to create a menu. We can follow the first three steps of the previous recipe, Appearing and disappearing menu.
  2. Next, select Appearing Menu and then click on Add Property inside of the Animation window. Once again, Unity asks us to save the animation, so we can simply select a folder and save the animation by naming it IdleAnimation.
  3. Now, in the Animation view, select the Rec button if it is not already selected in Unity. Also select Appearing Menu. Go to Inspector | Image (Script) component and change the color. For now, we will set it to green.
  4. At the beginning of the Animation window, at 0 key frame, there is now the color key frame. Just move the red bar to 1 second, which means 60th key frame for 60 samples, and change the color again in the Inspector. In this example, we will use blue.
  5. Now, select the first key frame at the beginning and press Ctrl + C to copy it. Next, move the red bar to 2 seconds, which means 120th key frame for 60 samples, and press Ctrl + V to paste it. By doing this, we can be certain that the last key frame is the same as the first one. Now, the animation is ready to be played as a loop.
  6. Since IdleAnimation is set as a loop by default and the autogenerated animator has to handle just one animation, we don't need to do anything other than clicking on the Rec button again to deactivate the recording mode. Finally, we can click on play to see that our menu changes its background color over time.

How it works...

Here, we created an animation that is ready to be played as a loop. This means that the last key frame is equal to the first one. In fact, when Unity plays the animation and it reaches the last frame, it is restarted from the beginning. So once it starts again, it's important to give an illusion of continuity. Therefore, since standing animations are always played as a loop, this is an important step. In fact, we also copied the key frame so that the first and the last key frames are identical.

Furthermore, for creating an idle animation, we are not limited to changing just the color of the background. In fact, we can create anything that we wish; our only limitation is our imagination. Just keep in mind that the animations need to be ready to be played as a loop.

The first key frame equals the last one.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.33.235