Hi, I'm trying to make a GUI Label fade out after a certain amount of time and I need some help on how to do it, preferably in JavaScript.
- To make the label transparent you need to change GUI.color.
- To wait a fixed time, use coroutines with WaitForSeconds or alternatively Invoke.
- Use a coroutine to reduce color alpha over time.
Some javascript:
var color : Color;
function Start()
{
color = Color.white;
yield FadeOutAfterTime(3);
}
function OnGUI()
{
GUI.color = color;
GUILayout.Label("Hai!");
// You probably want to restore GUI.Color here
}
function FadeOutAfterTime(time : float)
{
yield WaitForSeconds(time);
yield Fade();
}
function Fade()
{
while (color.a > 0)
{
color.a -= Time.deltaTime;
yield;
}
}