How it works...

This recipe animates the color of an Image component (a part of Unity's UI). We can animate the alpha parameter to fade the transparency of an Image. It allows us to create a fade in/fade out effect very easily. This recipe has some other key elements:

  • FadeAnimator empty game object: Our BlackScreen game object (containing the Image component) is a child of an empty game object (named FadeAnimator in this example). The empty game object has the Animator component attached. This way we can disable and enable the BlackScreen game object in our animations (it wouldn't be possible if the Animator component would be attached to the same  BlackScreen game object).
  • Disabling and enabling the BlackScreen game object: It is a good practice to disable our black screens because they can block mouse input for UI elements if they are enabled (even if they are fully transparent).
  • BlackScreen in the bottom of the Hierarchy: Our BlackScreen object should be placed in the very bottom of the Hierarchy to cover all other UI elements in our game.
..................Content has been hidden....................

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