IEnumerator FlyInCoroutine(IList <Cabinet> cabinets, System.Action onComplete) { flyIns.Clear(); this.onComplete = onComplete; Vector2 spawnPosition = (canvas.transform as RectTransform).rect.center; foreach (Cabinet cabinet in cabinets) { UIItem item = Instantiate <UIItem>(itemPrefab, canvas.transform, false); item.transform.position = UIUtil.ScreenToCanvas(canvas, new Vector3(Screen.width * 0.75f, Screen.height * 0.5f, 0f)); item.Fill(cabinet.GetItem()); SingleFlyIn flyIn = new SingleFlyIn { //delay = i * delayBetween, fadeInTime = fadeInTime, flyInTime = flyInTime, item = item, target = UIUtil.WorldToCanvas(canvas, cabinet.transform.position), targetObj = cabinet.gameObject }; flyIns.Add(flyIn); } flyIns.Sort((x, y) => { if (x.targetObj.transform.position.y == y.targetObj.transform.position.y) { return(x.targetObj.transform.position.x.CompareTo(y.targetObj.transform.position.x)); } return(y.targetObj.transform.position.y.CompareTo(x.targetObj.transform.position.y)); }); for (int i = 0; i < flyIns.Count; i++) { flyIns[i].delay = i * delayBetween; flyIns[i].Start(); } float startTime = Time.time; bool allDone = false; while (!allDone) { allDone = true; float time = Time.time - startTime; foreach (SingleFlyIn flyIn in flyIns) { flyIn.Update(time); allDone = allDone && flyIn.isDone; } yield return(null); } while (!Input.anyKeyDown) { yield return(null); } FlyInComplete(); }