private void Update() { Vector2 previous = Vector2.zero; LinkedListNode <NotificationPanel> lastAlive = null; bool needRemove = false; int i = 0; float cumulatedHeight = 0f; float previousHeight = 0f; for (LinkedListNode <NotificationPanel> it = notifications.First; it != null; it = it.Next) { NotificationPanel notif = it.Value; cumulatedHeight += notif.rectTransform.rect.height; if (Time.time <= notif.startTime + fadeDuration) { notif.rectTransform.anchoredPosition = Vector2.Lerp(spawnPosition, cumulatedHeight * Vector2.up - spawnPosition, (Time.time - notif.startTime) / fadeDuration); notif.SetAlpha((Time.time - notif.startTime) / fadeDuration); } else { notif.rectTransform.anchoredPosition = (previousHeight + notif.rectTransform.rect.height) * Vector2.up - spawnPosition; if (Time.time < notif.startTime + fadeDuration + displayDuration) { } else if (Time.time <= notif.stopTime) { notif.SetAlpha((notif.stopTime - Time.time) / fadeDuration); } else { Destroy(notif.gameObject); if (!needRemove) { lastAlive = it.Previous; needRemove = true; } } } previousHeight = notif.rectTransform.anchoredPosition.y; ++i; } if (needRemove) { while (notifications.Last != lastAlive) { notifications.RemoveLast(); } } }