What I want the code to do below is to fade in a piece of text, fade it out. Change the text, then repeat. I have a variable which gets added to each time the text is faded out so that when it fades in, it has changed. The fading in and out works fine, I haven’t tried to see if changing the text works but the main problem is repeating.
I have a line of code at the bottom of the FadeOut function telling it to start the FadeIn function but it gives me an error:
“Definition of ‘Controls.FadeOut()’ depends on ‘Controls.FadeIn()’ whose type could not be resolved because of a cycle. Explicitly declare the type of either one to break the cycle.”
This is because both functions sort of depend on each other and so the compiler cannot generate the code for both.
All I want is a to repeat a function when a different function ends, for the text to change when it ends as well, and for it to fade in and out smoothly. Could someone tell me how I could fix this problem? Thank you!
My script:
var nextText = 0;
function Start ()
{
GetComponent.<TextMesh>().color.a = 0;
yield WaitForSeconds (5);
FadeIn ();
}
function FadeIn ()
{
while (GetComponent.<TextMesh>().color.a < 1)
{
GetComponent.<TextMesh>().color.a += 1.5 * Time.deltaTime * 2;
yield;
}
yield WaitForSeconds (5);
FadeOut ();
}
function FadeOut ()
{
while (GetComponent.<TextMesh>().color.a > 0)
{
GetComponent.<TextMesh>().color.a -= 1.5 * Time.deltaTime * 2;
yield;
}
yield WaitForSeconds (5);
nextText ++;
FadeIn ();
}
function Update ()
{
if (nextText == 0)
{
GetComponent.<TextMesh>().text = "Right click to turn your torch on!";
}
if (nextText== 1)
{
GetComponent.<TextMesh>().text = "Press Spacebar to jump!";
}
if (nextText== 2)
{
GetComponent.<TextMesh>().text = "Press E to pick up objects!";
}
}