/// <summary> /// Chooses a living target. Final Target (destiny) is set by a child class of Unit /// Each Unit decides what is your preferred final target /// </summary> public virtual void chooseTarget(Node _finalTargetNode = null) { //set the final target finalTarget = _finalTargetNode; //remove unit from previous and current cells if (previousTarget != null) { previousTarget.GetComponent <Cell>().removeWalkingUnit(this); } if (currentTarget != null) { currentTarget.GetComponent <Cell>().removeWalkingUnit(this); } //go back to previous target currentTarget = previousTarget; //source cell Node sourceCell = CurrentTarget == null ? OriginSpawnedCell : CurrentTarget; //---- //get the path currentNodeIndex = 0; //restart a new path path = PathFinding.BFS(GridGenerator.instance.Grid, sourceCell, FinalTarget, GridGenerator.instance.Width, GridGenerator.instance.Height); noTarget = path.Count == 0; setNextTarget(); //get next target cell to go //---- }