I’m having a problem with a for loop that is only executing once:
BuildingCell SelectCellByWeight()
{
int highestWeight = 1;
List<BuildingCell> possibleCells = new List<BuildingCell>();
for(int x = 0; x < cellMap.GetLength(0); x++)
{
for(int y = 0; y < cellMap.GetLength(1); y++)//Only running once.
{
Debug.Log("YCell");
int currentWeight = weightMap[x, y];
if(currentWeight > highestWeight)
{
possibleCells.Clear();
highestWeight = currentWeight;
Debug.Log("Clear");
}
if(currentWeight == highestWeight)
{
possibleCells.Add(cellMap[x, y]);
}
}
}
int index = randomGenerator.Next(0, possibleCells.Count);
return possibleCells[index];
}
Cellmap is a 2D array of BuildingCells and weightMap is a 2D array of ints. Debug.log on both shows that they have their full size. Is there a problem in this section, or does it have to be somewhere else in the code.