private void DoThings() { if (!intialized) { return; } if (!IsPerformingAction && Player != null) { DestinationTile = Player.GetComponent <PlayerData>().CurrentTile; int shortestDistance = PathNode.GetDistanceToNode(CurrentTile, DestinationTile, GameGrid); foreach (GameObject go in Player.GetComponent <PlayerData>().AllStructures) { int distance = PathNode.GetDistanceToNode(CurrentTile, go.GetComponent <StructureData>().CurrentTile, GameGrid); if (distance < shortestDistance) { shortestDistance = distance; DestinationTile = go.GetComponent <StructureData>().CurrentTile; } } Tile realDestination = DestinationTile; if (shortestDistance > 4) { /*Debug.Log(CurrentTile.WalkableNeighbours.Count + ", " + CurrentTile.Neighbours.Count); * foreach (KeyValuePair<Tile.Sides, Tile> t in CurrentTile.Neighbours) { * Debug.Log(t.Value.IsWalkable); * } */ if (CurrentTile.WalkableNeighbours.Count > 0) { DestinationTile = CurrentTile.WalkableNeighbours[Random.Range(0, CurrentTile.WalkableNeighbours.Count)]; if (DestinationTile.WalkableNeighbours.Count > 0) { do { DestinationTile = DestinationTile.WalkableNeighbours[Random.Range(0, DestinationTile.WalkableNeighbours.Count)]; } while (DestinationTile == CurrentTile); } // Debug.Log(CurrentTile.Index + ", " + DestinationTile.Index + ", " + Player.GetComponent<PlayerData>().CurrentTile.Index); } else { return; } } //Debug.Log("???????"); TileTobeMovedTo = CalculatePath(); if (TileTobeMovedTo != CurrentTile && TileTobeMovedTo != DestinationTile && TileTobeMovedTo.Structure.Value == null && (TileTobeMovedTo.CurrentGameObject == null || TileTobeMovedTo.CurrentGameObject == this.gameObject)) { TypeOfPerformingAction[PlayerActions.Move] = true; Vector3 dest = TileTobeMovedTo.Position; Animator animCtrl = this.gameObject.GetComponent <Animator>(); if (dest.x > Position.x) { animCtrl.ResetTrigger("GoLeft"); animCtrl.SetTrigger("GoRight"); direction = 1; } else if (dest.x < Position.x) { animCtrl.ResetTrigger("GoRight"); animCtrl.SetTrigger("GoLeft"); direction = -1; } IsPerformingAction = true; CurrentTile.CurrentGameObject = null; TileTobeMovedTo.CurrentGameObject = this.gameObject; } else if (CurrentTile.IsAdjacent(realDestination)) { if ((realDestination.CurrentGameObject != null && realDestination.CurrentGameObject.GetComponent <EnemyData>() == null || realDestination.Structure.Value != null)) { if (realDestination.Structure.Value != null) { AttackTarget = realDestination.Structure.Value; } else { AttackTarget = realDestination.CurrentGameObject; } } TypeOfPerformingAction[PlayerActions.Attack] = true; IsPerformingAction = true; Player.GetComponent <PlayerData>().DiscoverTiles(); } } }