public List <int> FindPath(int startCellIndex, int endCellIndex) { worldMapGlobe.ClearCells(true, false, false); List <int> cellIndices = worldMapGlobe.FindPath(startCellIndex, endCellIndex); if (cellIndices == null) { return(null); // no path found } //This might be a redundant check if (cellIndices.Count == 0) { cellIndices = null; return(null); } List <int> finalPath = new List <int>(); finalPath.Add(cellIndices[0]); //Check that there is enough remaining movement to travel path //Start by getting the cost between the starting cell and the first cell in the path int neighborIndex = worldMapGlobe.GetCellNeighbourIndex(startCellIndex, cellIndices[0]); int pathCost = worldMapGlobe.GetCellNeighbourCost(startCellIndex, neighborIndex); int i = 0; //Get the cumlative cost for the rest of the path foreach (int cellIndex in cellIndices) { if (i < (cellIndices.Count - 1)) { neighborIndex = worldMapGlobe.GetCellNeighbourIndex(cellIndices[i], cellIndices[i + 1]); pathCost = pathCost + worldMapGlobe.GetCellNeighbourCost(cellIndices[i], neighborIndex); if (pathCost <= TravelRange) { finalPath.Add(cellIndices[i + 1]); } else { return(finalPath); } i++; } } return(finalPath); }