hi. I have this small problem to do some automatic update on a guitext. what i want to do is, to update a guitext after 3 seconds constantly until the game finish. the value would be incrementing one by one after 3 seconds.
Class guitextautoupdate{
private int _i;
System.Collections.IEnumerator yieldConnect() {
_i++;
Guitext.text = _i.ToString();
yield return new WaitForSeconds(3);
}
void Start()
{
StartCoroutine(yieldConnect( ));
}
}
What i think is, this code will update the text after 3 seconds.
but it doesnt do it.
You just need to make your coroutine have a while loop if you want it to go forever:
IEnumerator yieldConnect()
{
while(true)
{
// your code
yield return new WaitForSeconds(3);
}
}
You can also use a condition, like `while(i < 10)` or something like that. You can also break out of the while loop (and thus, end the coroutine), with the `break;` keyword.