I want to update the waitforseconds in runtime, is this somehow possible without restarting the IEnumerator? Or is there another way to get this to work?
void Update()
{
animationwait = (1 / jpm) * 60;//this is infinity at start so the coroutine stops and decreases later on when increasing jpm
if (jpm > 0 && !CoroutineIsRunning) {StartCoroutine("Animations");}
if(lastanimationwait != animationwait)//to update the coroutine
{
StopCoroutine("Animations");
CoroutineIsRunning = false;
lastanimationwait = animationwait;
StartCoroutine("Animations");
}
}
public IEnumerator Animations()
{
while(true)
{
CoroutineIsRunning = true;
yield return new WaitForSeconds(animationwait);
// change animations later with skills and stuff;
babe.animation["Idle"].speed = 1.0f;
babe.animation.Play ("Idle");
}
}
I hope you can help me with that. Thanks in advance.