I am unable to get rid of the error in this function, even after using the code provided in the references. It’s throwing the error of “not all code paths return a value”. I’m not sure what his means. If anyone could help me spot the error that would be great.
{
List<GridPosition> validGridPositionList = new List<GridPosition>();
GridPosition unitGridPosition = unit.GetGridPosition();
for (int x = -maxShootDistance; x <= maxShootDistance; x++)
{
for (int z = -maxShootDistance; z <= maxShootDistance; z++)
{
GridPosition offsetGridPosition = new GridPosition(x, z);
GridPosition testGridPosition = unitGridPosition + offsetGridPosition;
if (!LevelGrid.Instance.IsValidGridPosition(testGridPosition))
{
continue;
}
int testDistance = Mathf.Abs(x) + Mathf.Abs(z);
if (testDistance > maxShootDistance)
{
continue;
}
if (!LevelGrid.Instance.HasAnyUnitOnGridPosition(testGridPosition))
{
// Grid Position is empty, no Unit
continue;
}
Unit targetUnit = LevelGrid.Instance.GetUnitAtGridPosition(testGridPosition);
if (targetUnit.IsEnemy() == unit.IsEnemy())
{
// Both Units on same 'team'
continue;
}
validGridPositionList.Add(testGridPosition);
}
return validGridPositionList;
}
}