help
Root Question Message
ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
int i = 1;
List<Object> cityObjects = new List<Object>();
foreach(feature cityData in cities.features)
{
if (cityObjects[i] == null)
{
CityData tCity = SetCityVars(cityData);
GameObject citiesObject = new GameObject($"City {i}");
citiesObject.transform.parent = transform;
Object cityToUse;
//float? cityRadius;
if (tCity.POP_MAX <= 500000 && tCity.POP_MAX > 0)
{
cityToUse = CityTo500K;
}
else if (tCity.POP_MAX <= 1000000 && tCity.POP_MAX > 500000)
{
cityToUse = CityTo1M;
}
else if (tCity.POP_MAX > 1000000)
{
cityToUse = CityToRest;
}
else
{
cityToUse = CityTo500K;
}
CoordinateDegrees coordinate = new CoordinateDegrees(tCity.coordinates[0], tCity.coordinates[1]);
Vector3 cityPosition = coordinate.CoordinateToPoint(coordinate);
Vector3 cityDirection = citiesObject.transform.position - cityPosition;
Quaternion cityRotation = Quaternion.LookRotation(cityDirection);
Object CityMesh = Object.Instantiate(cityToUse, cityPosition, cityRotation, citiesObject.transform);
cityObjects.Insert(i, CityMesh);
i += 1;
}
cityObjects[i]
at the start of the foreach loop, cityObjects
likely doesn't have anything at element [1]
, the initial value of i
var x = new List<object>() { null, null, null }'
etcObject[] cityCheck = new Object[cities.features.Length];