Creating a message that fades away
Sometimes, we want a message to only be displayed for a certain time, and then fade away and disappear. This recipe will describe the process for displaying a text message and then making it fade away completely after 5 seconds. It could be used for providing instructions or warnings to a player that disappears so as not to take up screen space.
Getting ready
This recipe adapts the previous one (Displaying a digital countdown timer). So, make a copy of the project for that recipe and work on that copy.
How to do it...
To display a text message that fades away, follow these steps:
- In the Inspector panel, remove the scripted component, DigitalCountdown, from the Text-clock GameObject.
- Select the Text-clock GameObject in the Hierarchy panel. Then, in the Inspector for the TextMeshPro – Text (UI) component, set its Text Input default text to
hello world
. - Create a C# script class called
FadeAway
that contains...