void HandleEnemyMove(GridItem item) { if (item.GetItemType() != ItemType.Regular) { return; } if (playerMoves.Contains(item)) { return; } else { playerMoves.Add(item); } var LastItemTouched = playerMoves[playerMoves.Count - 1]; targetsPosition = new List <Vector3> (); targetsPosition = levelConfig.GetTargetsPositions(currentLevel); allTargetsPath = new List <List <GridItem> > (); // int targetXPos = (int)levelConfig.GetTargetPosition ().x; // int targetYPos = (int)levelConfig.GetTargetPosition ().y; // GridItem goal = gridItems[targetXPos,targetYPos]; foreach (Enemy enemy in enemies) { int enemyX = (int)enemy.GetGridPos().x; int enemyY = (int)enemy.GetGridPos().y; if (CheckWinCondition(gridItems [enemyX, enemyY], targetsPosition)) { return; } foreach (var target in targetsPosition) { if (IsTargetReachable(gridItems[enemyX, enemyY], gridItems[(int)target.x, (int)target.y])) { ClearOldPath(); originalPath = new List <List <GridItem> > (); Traverse(gridItems [enemyX, enemyY], gridItems [(int)target.x, (int)target.y]); pathToMoveTo = new List <GridItem> (); pathToMoveTo = FindShortPath(gridItems [enemyX, enemyY], gridItems [(int)target.x, (int)target.y]); allTargetsPath.Add(pathToMoveTo); } } if (allTargetsPath.Count > 1) { pathToMoveTo = new List <GridItem>(); pathToMoveTo = FindClosesetTargetPath(); } int firstMoveX = (int)pathToMoveTo[1].GetGridPos().x; int firstMoveY = (int)pathToMoveTo[1].GetGridPos().y; enemy.MoveToNewPosition(firstMoveX, firstMoveY, gridItems [firstMoveX, firstMoveY]); levelFail = CheckFailCondition(enemy, targetsPosition); if (levelFail) { RemoveItemsListener(); StartFailLevelAnimation(); } } }