I'm attempting to grow and then shrink a series of gameobjects using two different lerps within a coroutine. Despite the two while loops being functionally identical, the objects will grow but not shrink afterwards, instead remaining at their increased size.
I've substituted hard-coded values for the initial and final sizes, but the problem still persists. I've tested and found that both loops are executing fine, and the program does not get stuck in either loop.
Is there some fundamental misunderstanding I have of the nature of lerps or coroutines?
initialSize = transform.localScale.x;
finalSize = 2f * initialSize;
float elapsedTime = 0f;
while (elapsedTime < trap.pulsateTime)
{
transform.localScale = Vector3.Lerp(transform.localScale, finalSize * Vector3.one, (elapsedTime / trap.pulsateTime));
yield return new WaitForEndOfFrame();
elapsedTime += Time.deltaTime;
}
elapsedTime = 0f;
while (elapsedTime < trap.pulsateTime)
{
transform.localScale = Vector3.Lerp(transform.localScale, initialSize * Vector3.one, (elapsedTime / trap.pulsateTime));
yield return new WaitForEndOfFrame();
elapsedTime += Time.deltaTime;
}