public void SpawnChunk(int x, int y, int z)
    {
        VoxelPosition worldPos = new VoxelPosition(x, y, z);

        if (loadedChunks.ContainsKey(worldPos))
        {
            return;
        }

        //Instantiate the chunk at the coordinates using the chunk prefab
        GameObject newChunkObject = Instantiate(
            chunkPrefab, new Vector3(x * scaleFactor, y * scaleFactor, z * scaleFactor),
            Quaternion.Euler(Vector3.zero),
            this.transform
            ) as GameObject;

        newChunkObject.name = "Chunk at (" + x + ", " + y + ", " + z + ")";

        Chunk newChunk = newChunkObject.GetComponent <Chunk>();

        newChunk.position = worldPos;
        newChunk.map      = this;
        newChunk.MoveIntoPlace();
        newChunk.scaleFactor = scaleFactor;
        newChunk.chunkSize   = chunkSize;
        loadedChunks.Add(worldPos, newChunk);
    }
 private void UpdateIfEqual(int value1, int value2, VoxelPosition pos)
 {
     if (value1 == value2)
     {
         Chunk chunk = GetChunk(pos.x, pos.y, pos.z);
         if (chunk != null)
         {
             chunk.ForceUpdate();
         }
     }
 }
    public Chunk GetChunk(int x, int y, int z)
    {
        VoxelPosition pos      = new VoxelPosition();
        float         multiple = chunkSize;

        pos.x = Mathf.FloorToInt(x / multiple) * chunkSize;
        pos.y = Mathf.FloorToInt(y / multiple) * chunkSize;
        pos.z = Mathf.FloorToInt(z / multiple) * chunkSize;
        Chunk containerChunk = null;

        loadedChunks.TryGetValue(pos, out containerChunk);

        return(containerChunk);
    }