Hi,
I am trying to display something like a subtitle, the guiText.text changes at certain seconds.
What I am having trouble with is, I can not fade the guiText out - change it - fade it back in. I am pretty sure there is a very simple way to do this, I have looked into yield, coroutines and tried everything I could think of. Here is what I have:
function LateUpdate () {
seconds=GameObject.Find("Timer").GetComponent("Timer").seconds;
switch(seconds){
case 0:
fadeOut();
fadeIn();
print("second 0");
guiText.text="Lascia Chi'o Pianga";
break;
case 6:
print("6th second");
fadeOut();
fadeIn();
guiText.text="Mia Crudo, Sorte";
break;
default:
//guiText.text=guiText.text;
break;
}
and of course the fadeIn and fadeOut functions
function fadeIn(){
guiText.material.color.a=Mathf.Lerp(0,1,Time.time);
yield WaitForSeconds(1);
}
function fadeOut(){
guiText.material.color.a=Mathf.Lerp(1,0,Time.time);
yield WaitForSeconds(1);
}
What I was hoping for was, that the yield WaitForSeconds statements would interrupt the LateUpdate. What happens is that, the first line fades in perfectly, stays on screen, then when case 6 is true, the second line kicks in instantly.
So, the first FadeIn works, the rest doesn't? I am not sure what is going on.
Thanks in advance :)