void ChooseShortestPath () {
//
// When pathsForAll is false there will only be one non-null path
chosenTarget = -1;
if (nodePaths != null) {
uint bestG = int.MaxValue;
for (int i = 0; i < nodePaths.Length; i++) {
var currentPath = nodePaths[i];
if (currentPath != null) {
// Get the G score of the first or the last node in the path
// depending on if the paths are reversed or not
var g = pathHandler.GetPathNode(currentPath[inverted ? 0 : currentPath.Count-1]).G;
if (chosenTarget == -1 || g < bestG) {
chosenTarget = i;
bestG = g;
}
}
}
}
}