- Home /
Question by
MattSawrey · Aug 06, 2014 at 11:00 PM ·
colortransparencyalphagui.label
Fading alpha of specific GUI.Label
The script below is intended to create a red GUI.label that fades over the course of two seconds when certain buttons are pressed. It's called when buttons are pressed within my OnGUI function, but it's not showing anything in-game. I know the function is being called and that the GUI alpha value is being modified correctly through Debug.Log checks, so I'm having difficulty finding the problem. Can anybody help?
(guiRed is a red, square texture by the way. Just in-case that helps)
void ButtonFailed (Rect button)
{
float start = 1.0f;
float end = 0.4f;
float length = 2.0f;
float guiAlpha;
for(float i = 0; i < 1; i += Time.deltaTime*(1/length))
{
guiAlpha = Mathf.Lerp(start, end, i);
GUI.color = new Color {a = guiAlpha};
GUI.Label(button, guiRed);
GUI.color = new Color {a = 1.0f};
}
}
Thanks in advance.
Matt
Comment