public static void RemoveBlock(int x, int y, int z) { if (x < 0 || y < 0 || z < 0 || x > width * chunkSize - 1 || y > height * chunkSize - 1 || z > depth * chunkSize - 1) { return; } if ((blocks [x, y, z] >> 8) == 0) { return; } Chunk chunk = GetChunk(x, y, z); if (chunk != null) { if (!chunk.dirty) { chunk.dirty = true; rebuildList.Add(chunk); } } if (Random.value > 0.75) { BlockPool.AddBlock(x, y, z, blocks [x, y, z], 1); } blocks[x, y, z] = 0; }
public void CollisionExplode() { this.noOfCollisions++; Vector3 pos = this.obj.GetComponent <MeshCollider> ().transform.position; //if (this.noOfCollisions > 10 && this.blocks.Length < 300) { // TBD: foreach block in chunk for (int x = 0; x < this.toX; x++) { for (int y = 0; y < this.toY; y++) { for (int z = 0; z < this.toZ; z++) { if (this.blocks [x, y, z] != 0) { if (Random.value > 0.5) { // TBD: Apply rotation. BlockPool.AddBlock((int)pos.x + x, (int)pos.y + y, (int)pos.z + z, this.blocks[x, y, z], 1, 0.001f); } } } } } GameObject.Destroy(this.obj); //} else if(this.noOfCollisions > 10 ){ // // Remove random blocks // int noOfBlocks = (int)Random.Range(1,this.blocks.Length/2); // for(int i = 0; i < noOfBlocks; i++) { // int x = (int)Random.Range (0, toX); // int y = (int)Random.Range (0, toY); // int z = (int)Random.Range (0, toZ); // if (this.blocks [x, y, z] != 0) { // this.blocks [x, y, z] = 0; // BlockPool.AddBlock ((int)pos.x + x, (int)pos.y + y, (int)pos.z + z, this.blocks[x,y,z], 1, 0.001f); // } // } // position = pos; // World.RebuildChunks (this); // } //} }