Skip to content

Instantly share code, notes, and snippets.

@fesoliveira014
Created August 4, 2016 16:47
Show Gist options
  • Save fesoliveira014/b765e3b69b7ae059c2c20e4a43b87cc5 to your computer and use it in GitHub Desktop.
Save fesoliveira014/b765e3b69b7ae059c2c20e4a43b87cc5 to your computer and use it in GitHub Desktop.
private IEnumerator UpdateChunks(){
for (int i = 1; i < VIEW_RANGE; i += ChunkWidth) {
float vr = i;
for (float x = transform.position.x - vr; x < transform.position.x + vr; x += ChunkWidth) {
for (float z = transform.position.z - vr; z < transform.position.z + vr; z += ChunkWidth) {
_pos.Set(x, 0, z); // no y, yet
_pos.x = Mathf.Floor(_pos.x/ChunkWidth)*ChunkWidth;
_pos.z = Mathf.Floor(_pos.z/ChunkWidth)*ChunkWidth;
Chunk chunk = Chunk.FindChunk(_pos);
// If Chunk is already created, continue
if (chunk != null)
continue;
// Create a new Chunk..
chunk = (Chunk) Instantiate(ChunkFab, _pos, Quaternion.identity);
}
}
// Skip to next frame
yield return 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment