// Update is called once per frame void Update() { Vector3 position = transform.position; currentChunkPos = new Vector3Int(Mathf.FloorToInt(position.x / 10), Mathf.FloorToInt(position.y / 10), Mathf.FloorToInt(position.z / 10)); if (lastChunkPos != currentChunkPos) { lastChunkPos = currentChunkPos; for (int x = -renderDistance; x < renderDistance; x++) { for (int z = -renderDistance; z < renderDistance; z++) { for (int y = -renderDistance; y < renderDistance; y++) { loadedChunks.Add((new Vector3Int(x, y, z) + currentChunkPos)); terrain.ChunkLoadUpdate(Vector3.Distance(new Vector3Int(x, y, z) + currentChunkPos, currentChunkPos), new Vector3Int(x, y, z) + currentChunkPos); } } } foreach (var oldChunk in lastLoadedChunks) { if (!loadedChunks.Contains(oldChunk)) { terrain.UnloadChunk(oldChunk); } } foreach (var newChunk in loadedChunks) { if (!lastLoadedChunks.Contains(newChunk)) { terrain.LoadChunk(newChunk); } } lastLoadedChunks = new List <Vector3Int>(loadedChunks); loadedChunks.Clear(); } //transform.Translate(Vector3.forward * Time.deltaTime * 10f); }