WaitForSeconds(0) not returning

I have this code running in foreach loop

	foreach (DrawPart item in objectParts) {
				item.order = order++;
				item.PartCollided += RemoveDrawPart;
				item.enableCollider();
				StartCoroutine(item.appearInSecondsWithDelay(1f,0f));
  }

which I want to delay the appearing of this object by delaying it with yield return new WaitForSeconds() as the following:

	public IEnumerator appearInSecondsWithDelay (float seconds, float delay = 0)
	{
		if (this.GetComponent<Transform> () != null) {

			yield return new WaitForSeconds(delay);
			
			var originalScale = this.transform.localScale;
//			Debug.Log(originalScale);
			this.transform.localScale = Vector3.zero;

			var time = seconds;
			var originalTime = time;

			while (time > 0.0f) {
				time -= Time.deltaTime;
				transform.localScale = Vector3.Lerp (originalScale, Vector3.zero, time / originalTime);
        // Debug.Log("loopScale:" + time);
        yield return null;
			}
		}
		yield break;
	}

but it’s not even returning even the waiting second is 0.

while (time > 0.0f) {
time -= Time.deltaTime;
transform.localScale = Vector3.Lerp (originalScale, Vector3.zero, time / originalTime);
// Debug.Log(“loopScale:” + time);
yield return null;
}

In this section, the

“yield return null;”

should be

“yield return new WaitForEndOfFrame();”

Currently you are waiting “null”==no time in your while loop, therefore the change will always be “instant”.


Also i would recommend adding the line below the While loop, to set the scale to fix value at the end:

transform.localScale = originalScale;