The documentation is a bit vague on this point, and I thought I’d ask on here before I went and blew my compiler up…
What happens when a coroutine is called which is already running?
e.g.
say I have this code set up in a coroutine: (note: this requires other code to work, but it’ll make the point)
IEnumerator basicIdea
{
while(target!=null)
{
transform.rotation = Quaternion.Slerp(transform.rotation, rot, Time.deltaTime * turnSpeed);
transform.position += transform.forward * speed * Time.deltaTime;
}
yield break;
}
what would happen if I had a function such as:
void CoroutineInvokation
{
startCoroutine(basicIdea);
}
…and the invoking function was in a position to be called again before the coroutine finishes?
would it be more appropriate to do something like this?:
void CoroutineInvokation
{
stopCoroutine(basicIdea);
startCoroutine(basicIdea);
}
Basically what this comes down to is…will a new instance of a coroutine be created when it is called again or will it reset the existing one?