Index out... Fix

This commit is contained in:
brausjonas
2022-05-17 23:13:22 +02:00
parent f23fc16f0d
commit ed4f60bfdb
2 changed files with 13 additions and 8 deletions
Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 18 KiB

+13 -8
View File
@@ -145,16 +145,21 @@ public class World : MonoBehaviour
{ {
for (int z = playerChunk.z - Data.viewDistance; z < playerChunk.z + Data.viewDistance; z++) for (int z = playerChunk.z - Data.viewDistance; z < playerChunk.z + Data.viewDistance; z++)
{ {
if(chunks[x, z].gameObject == null) if(z >= 0 && x >= 0 && z < worldSize && x < worldSize)
{ {
chunks[x, z].Initialize(); if (chunks[x, z].gameObject == null)
chunks[x, z].gameObject.transform.SetParent(gameObject.transform); {
chunks[x, z].Initialize();
chunks[x, z].gameObject.transform.SetParent(gameObject.transform);
}
if (!chunks[x, z].active)
{
chunksToUpdate1.Enqueue(new ChunkCoord(x, z));
}
checkList.Add(chunks[x, z]);
} }
if(!chunks[x, z].active)
{
chunksToUpdate1.Enqueue(new ChunkCoord(x, z));
}
checkList.Add(chunks[x, z]);
} }
} }