private IEnumerator fall() { for (int i = 0; i < waitFramesBeforeFall; i++) { yield return(null); } if (GridCell != null) { removeFromCell(); fallToCell.awaitingFallingTile = this; } bool stillFalling = true; while (stillFalling) { if (fallToCell.Grid.Rotating) { float bestDist = -1; TileGridCell bestCell = null; while (bestCell == null) { foreach (var cell in fallThroughTiles) { var sqrDist = (transform.position - cell.transform.position).sqrMagnitude; if (cell.Tile == null && cell.awaitingFallingTile && (bestDist < 0 || sqrDist < bestDist)) { bestDist = sqrDist; bestCell = cell; } } if (bestCell == null) { yield return(null); } } fallToCell.awaitingFallingTile = null; bestCell.Tile = this; parentToCell(bestCell, true); transform.localPosition = Vector3.zero; while (fallToCell.Grid.Rotating) { yield return(null); } fallRoutine = null; fallToCell = null; yield break; } // TODO Handle rotation. var localPos = transform.localPosition; //localPos.y -= maxFallSpeed; localPos -= transform.InverseTransformDirection(Vector3.up) * maxFallSpeed; if (transform.position.y < fallToCell.transform.position.y) { localPos = fallToCell.transform.localPosition; stillFalling = false; } transform.localPosition = localPos; yield return(null); } bool nowhereToFall = false; if ((fallToCell.awaitingFallingTile != null && fallToCell.awaitingFallingTile != this) || (fallToCell.Tile && fallToCell.Tile != this)) { nowhereToFall = true; } if (!nowhereToFall) { fallToCell.awaitingFallingTile = null; fallToCell.Tile = this; parentToCell(fallToCell, true); fallRoutine = null; fallToCell = null; LockedIn = true; HandleGridChange(); data.FallIntoPlace(this); if (rematchAfterFall) { yield return(null); if (GridCell != null) { GridCell.CheckForTriplet(); GridCell.Grid.StartCoroutine(GridCell.Grid.DetonateAndBurn(GridCell)); } } } else { Destroy(gameObject); } }