Created
August 4, 2016 16:47
-
-
Save fesoliveira014/b765e3b69b7ae059c2c20e4a43b87cc5 to your computer and use it in GitHub Desktop.
A chunk loading example from http://gamedev.stackexchange.com/questions/81235/how-to-load-stacking-chunks-on-the-fly
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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