To display a text message that fades away, follow these steps:
- In the Inspector window, remove the scripted component, DigitalCountdown, from the Text-clock GameObject.
- Create a C# script class called FadeAway that contains the following code, and add an instance as a scripted component to the Text-hello GameObject:
using UnityEngine;
using UnityEngine.UI;
[RequireComponent(typeof(CountdownTimer))]
public class FadeAway : MonoBehaviour
{
private CountdownTimer countdownTimer;
private Text textUI;
void Awake()
{
textUI = GetComponent<Text>();
countdownTimer = GetComponent<CountdownTimer>();
}
void Start()
{
countdownTimer.ResetTimer(5);
}
void Update()
{
float alphaRemaining =
countdownTimer.GetProportionTimeRemaining();
print(alphaRemaining);
Color c = textUI.color;
c.a = alphaRemaining;
textUI.color = c;
}
}
- When you run the scene, you...