private bool MoveBallToNewPositionIfCan(BallBehavior oldBall, Point start, Point end) { for (int x = 0; x < 9; x++) { for (int y = 0; y < 9; y++) { mapForPathFinding[x, y] = GameBoardManager.Instance.field[x, y] == null ? 0 : 1; } } mapForPathFinding[start.X, start.Y] = 0; var resultPath = pathSearcher.Search(mapForPathFinding, start, end); if (resultPath.Any()) { var oldPosition = GameBoardManager.Instance.GetPos(start.X, start.Y); Queue <GameObject> stepImages = new Queue <GameObject>(); if (ShowPath) { var firstStepImage = GetNextImage(new Vector3Combined { Start = oldPosition, End = GameBoardManager.Instance.GetPos(resultPath[0].X, resultPath[0].Y) }); stepImages.Enqueue(firstStepImage); GameState = GameState.Animation; oldBall.MoveByPath(resultPath.Select(pathStep => GameBoardManager.Instance.GetPos(pathStep.X, pathStep.Y)).ToArray(), () => { StartCoroutine(AfterBallMovedToNewPosition(stepImages, oldBall, start, end)); }, (movedPosition) => { GameObject stepImage = GetNextImage(movedPosition); if (stepImage != null) { stepImages.Enqueue(stepImage); } }); } else { GameState = GameState.Animation; oldBall.StartTeleport(() => { oldBall.transform.position = GameBoardManager.Instance.GetPos(end.X, end.Y); oldBall.StartShowingAnimation(() => { StartCoroutine(AfterBallMovedToNewPosition(stepImages, oldBall, start, end)); }); }); } return(true); } else { AudioManager.Instance.PlaySound(wrongPlace); return(false); } }