Hello everybody!
I have a problem that is driving me crazy! I'm generating a three-dimensional array, and when I run inside the Unity, or Android, everything works perfectly.
But when I run on iOS, happens IndexOutOfRangeException error when creating the array!
Anyone have any idea why?
void GenerateWorldData () {
WorldData = new byte[Width, Height, Depth];
_perlingNoise = new PerlingNoise(Seed, 15);
Debug.Log(WorldData.GetLength(0) + "," + WorldData.GetLength(1) + "," + WorldData.GetLength(2));
for (int x = 0; x < Width; x++)
{
for (int y = 0; y < Height; y++)
{
for (int z = 0; z < Depth; z++)
{
if (y >= 24 && y <= 24 + 2)
{
WorldData[x, y, z] = (byte)VoxelType.Occlusion;
}
else
{
int stone = _perlingNoise.GetPerlingNoise(x, z, 18) + 15;
int dirt = stone + _perlingNoise.GetPerlingNoise(x, z, 8) + 10;
int grass = dirt + 1;
if (y <= stone)
{
WorldData[x, y, z] = (byte)VoxelType.Stone;
}
else if(y <= dirt)
{
WorldData[x, y, z] = (byte)VoxelType.Dirt;
}
else if(y <= grass)
{
WorldData[x, y, z] = (byte)VoxelType.Grass;
}
else
{
WorldData[x, y, z] = (byte)VoxelType.Air;
}
}
}
}
Debug.Log(x);
}
Debug.Log("Finished");
}
And this is the error that appears on the xCode console:
IndexOutOfRangeException: Array index is out of range.
at (wrapper managed-to-managed) object:ElementAddr (object,int,int,int)
at World.GenerateWorldData () [0x00000] in :0
at World.CreateWorld () [0x00000] in :0
at World.Awake () [0x00000] in :0
(Filename: Line: -1)
↧