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.