Skip to content

Instantly share code, notes, and snippets.

@markedagain
Created May 5, 2013 01:06
Show Gist options
  • Save markedagain/5519317 to your computer and use it in GitHub Desktop.
Save markedagain/5519317 to your computer and use it in GitHub Desktop.
public static List<GameObject> getRoute(GameObject fromRoad , GameObject toRoad , GameObject lastRoad, List<GameObject> pathSoFar ){
List<GameObject> _tmpListRoad = GeneralHelper.findTilesNear(_roadList,fromRoad.transform.position,2);
for (int i = 0; i < _tmpListRoad.Count; i++) {
if (_tmpListRoad[i] == toRoad ){//we found our destination
pathSoFar.Add(_tmpListRoad[i]);
return pathSoFar;
}else{//nope lets make sure this tile is not where we currently are and try the next tile in connection
if (fromRoad != _tmpListRoad[i] && lastRoad != _tmpListRoad[i]){ //make sure this tile was not already verified
if (getRoute(_tmpListRoad[i],toRoad,fromRoad , pathSoFar) != null){
pathSoFar.Add(_tmpListRoad[i]);
return pathSoFar;
}
}
}
}
return null;//we did not find any new paths connecting to this road
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment