Hi,
I want to make a fade in and fade out animation, but I cannot seem to find a way to change the alpha of the “Fade” texture ONLY. Left like this, the code fades the “Background” texture as well and at t=2 there is nothing to see on the screen.
I know I can solve this problem by separating the two textures into separate scripts or making one of them a GUI Texture component, but I would like to have both in the same script.
Any help on this matter or suggestions on the code in general will be greatly appreciated.
Thank you!
///*Splash Vars*///
var Alpha:float;
/*Images*/
var Fade:Texture;
var Background:Texture;
///*Code*///
function Start()
{
audio.volume=PlayerPrefs.GetFloat("Volume");
yield FadeAnimation(1.0,0.0,2.0);
yield WaitForSeconds(2);
yield FadeAnimation(0.0,1.0,2.0);
Application.LoadLevel(Application.loadedLevel+1);
}
function OnGUI()
{
GUI.color.a=Alpha;
GUI.DrawTexture(Rect(0,0,Screen.width,Screen.height),Fade);
GUI.DrawTexture(Rect(0,0,Screen.width,Screen.height),Background);
}
function FadeAnimation(AlphaStart:float,AlphaEnd:float,Duration:float)
{
for (var t:float=0.0;t<1.0;t=t+Time.deltaTime*1.0/Duration)
{
Alpha=Mathf.Lerp(AlphaStart,AlphaEnd,t);
yield;
}
}