Question by
scarcloud · Feb 01, 2018 at 07:10 PM ·
transformvector3coroutinelocalscale
transform.localScale in Coroutine grows exponentially
I have a Coroutine to make an object grow in size while a condition is true:
public bool conditionIsMet = false;
public float scalingFactor = 0.2f;
/*...*/
public float Begin()
{
conditionIsMet = true;
StartCoroutine(GrowInSize());
}
public float End()
{
conditionIsMet = false;
// Reset localScale;
transform.localScale = new Vector3(1f, 1f, 0.1f);
}
public IEnumerator GrowInSize()
{
while (conditionIsMet) {
transform.localScale += new Vector3(1, 1, 0) * scalingFactor;
yield return new WaitForEndOfFrame();
}
}
I start the Coroutine with a typical StartCoroutine(GrowInSize())
and kill it by setting the condition to false.
What I noticed is that with every start of the Coroutine, the growing speed increases exponentially. The first couple of iterations double the size of the transform after some seconds, while continous iterations push the speed so far that after about the 15th iteration, the size of the transform quadruples within half the time. Can somebody replicate this issue? What exactly is going on?
Comment