Fading the transparency of a material
A feature of many games is for objects to fade away so that they’re invisible, or so that they appear gradually until they’re fully visible. Unity provides a special rendering mode called Fade for this purpose.
In this recipe, we will create an object that, once clicked, fades out and disappears. We’ll also look at how to enhance the code so that it takes the GameObject’s own initial alpha value into account. This will make it self-destruct and destroy the GameObject completely when the object has faded out.
Getting ready
For this recipe, we have provided the script in the 05_06
folder.
How to do it...
Follow these steps:
- Create a new Unity 3D project.
- Create a sphere by choosing the menu GameObject | 3D Object | Sphere.
- In the Hierarchy panel, you can select the Sphere GameObject and see its collider component in the Inspector panel. All the 3D primitives such as cubes and...