IEnumerator SlideCoroutine() { IsAnimating = true; wasMoved = false; GameBoard.Current.CurrentState = GameBoard.GameState.Animating; while (true) { // Attempt to move towards the next tile movePct = 0; targetTileX = BoardX + SlideX; targetTileY = BoardY + SlideY; // Is this an acceptable move? if (targetTileX >= 0 && targetTileY >= 0 && targetTileX < GameBoard.Current.Cols && targetTileY < GameBoard.Current.Rows && GameBoard.Current.Board[targetTileY, targetTileX] == null) { // Then move us there now, and start animating GameBoard.Current.Board[BoardY, BoardX] = null; SetBlockPosition(targetTileX, targetTileY); } else { break; } // Animate movement lastPos = _t.localPosition; while (movePct < 1) { tmpPos = lastPos; tmpPos.x += (SlideX * movePct * GameBoard.Current.BlockSize); tmpPos.y += (SlideY * movePct * GameBoard.Current.BlockSize); _t.localPosition = tmpPos; movePct += SlideSpeed * Time.deltaTime * GameBoard.Current.DifficultyTimeScale; yield return(null); } // Stop and finish movement BoardX = targetTileX; BoardY = targetTileY; _t.localPosition = GameBoard.Current.GetLocalPosition(targetTileX, targetTileY); wasMoved = true; } IsAnimating = false; SoundBoard.PlayBlockSettle(); GameBoard.Current.CurrentState = GameBoard.GameState.Selecting; GameBoard.Current.ResetSelection(this, BoardX, BoardY); if (wasMoved) { GameBoard.Current.TestForClear(BoardX, BoardY); } }