- Home /
Any fade-in/fade-out animations for GUI Text?
I have a scene going where the GUI Texts get instantiated at different times. But when you play it, it looks way to rapid. How can I add a fade-in animation to make it smoother?
Comment
Answer by suresh2485 · Feb 20, 2013 at 05:26 AM
//I used four Images 1 and four are same image , AlphaValues are float
var mainMenuTex :Texture[];
var menuIndex:int = 0;
if(menuIndex ==0)
alphaValue -= Mathf.Clamp01(Time.deltaTime/10);
else if(menuIndex ==1)
alphaValue1 -= Mathf.Clamp01(Time.deltaTime/10);
else if(menuIndex ==2)
alphaValue2 -= Mathf.Clamp01(Time.deltaTime/10);
if(alphaValue <0 && menuIndex == 0)
{
menuIndex ++;
alphaValue = 0;
}
else if(alphaValue1 < 0 && menuIndex == 1)
{
menuIndex ++;
alphaValue1 = 0;
}
else if(alphaValue2 < 0 && menuIndex == 2)
{
menuIndex = 0;
alphaValue = 1.0f;
alphaValue1 = 1.0f;
alphaValue2 = 1.0f;
}
Debug.Log("alphaValue"+alphaValue);
GUI.color.a = 1.0 ;
GUI.DrawTexture(Rect(0, 0, Screen.width, Screen.height), mainMenuTex[3],ScaleMode.StretchToFill, true, 0.0F);
GUI.color.a = alphaValue2 ;
GUI.DrawTexture(Rect(0, 0, Screen.width, Screen.height), mainMenuTex[2],ScaleMode.StretchToFill, true, 0.0F);
GUI.color.a = alphaValue1 ;
GUI.DrawTexture(Rect(0, 0, Screen.width, Screen.height), mainMenuTex[1],ScaleMode.StretchToFill, true, 0.0F);
GUI.color.a = alphaValue ;
GUI.DrawTexture(Rect(0, 0, Screen.width, Screen.height), mainMenuTex[0],ScaleMode.StretchToFill, true, 0.0F);
GUI.color.a = 1.0 ;
Answer by Spy-King · Jul 23, 2016 at 09:59 PM
I think it will be easier to add a canvas group to the text (as well as an animation component), then make an animation which will change the alpha of the canvas group and thus the text in say 6 or 9 seconds.