public IEnumerator IMove(int steps, Tile[] path, float movementSpeed = 0.25f) { var targetPosition = Vector2.zero; var finalDestination = CurrentPathIndex + steps; var aniamtionID = 0; // Check if stone has already moved atleast once! if (CurrentPathIndex > -1 && CurrentPathIndex < path.Length - 1) { CurrentTile = path[CurrentPathIndex]; } if (CurrentTile != null && CurrentTile.OccupiedStone) { CurrentTile.ClearOccupiedStone(); } var destinationTile = path [ finalDestination > path.Length - 1 ? path.Length - 1 : finalDestination ]; while (CurrentPathIndex < finalDestination) { CurrentPathIndex++; if (CurrentPathIndex > path.Length - 1) { targetPosition = path[path.Length - 1].transform.position; aniamtionID = LeanTween.move(gameObject, targetPosition, movementSpeed) .setOnComplete(() => { LeanTween.scale(gameObject, Vector2.zero, movementSpeed) .setEaseInOutElastic() .setOnComplete(() => { gameObject.SetActive(false); }); }) .id; yield return(new WaitWhile(() => LeanTween.isTweening(aniamtionID))); } else { targetPosition = path[CurrentPathIndex].transform.position; } aniamtionID = LeanTween.move(gameObject, targetPosition, movementSpeed).id; yield return(new WaitWhile(() => LeanTween.isTweening(aniamtionID))); } CurrentTile = destinationTile; if (CurrentTile.OccupiedStone && CurrentTile.OccupiedStone.Owner.Index != Owner.Index) { var stoneToReturn = CurrentTile.OccupiedStone; targetPosition = stoneToReturn.StartPosition; aniamtionID = LeanTween.move(stoneToReturn.gameObject, targetPosition, movementSpeed).id; yield return(new WaitWhile(() => LeanTween.isTweening(aniamtionID))); stoneToReturn.CurrentPathIndex = -1; stoneToReturn.CurrentTile = null; } CurrentTile.PlaceStone(this); }