- Home /
Question by
ComeSweetDeath · Sep 05, 2014 at 04:38 PM ·
coroutinecoroutinesstopcoroutine
If I StopCoroutine("myCoroutine")', will the variable values in myCoroutine be reset?
Say I have something like:
function Update ()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
StopCoroutine("myCoroutine");
StartCoroutine("myCoroutine");
}
}
function myCoroutine ()
{
var t : float = 0;
while (t <= 1.0)
{
t += 0.1;
yield;
}
}
Will the StopCoroutine("myCoroutine") reset the "t" variable in the coroutine?? Much Thanks!
Comment
Best Answer
Answer by AyAMrau · Sep 05, 2014 at 04:47 PM
Yes, each call to StartCoroutine starts a new one, so everything will be executed from the top in the new coroutine, including any variable initialisation.
Your answer
![](https://koobas.hobune.stream/wayback/20220613162355im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to force Coroutine to finish 1 Answer
Flash image while ammo is low - coroutines? 3 Answers
Coroutines not passing yield 1 Answer
Collection Change During Iteration 0 Answers
Why doesnt my coroutine ever end? 2 Answers