Skip to content

Instantly share code, notes, and snippets.

@AndrewWeston9
Last active October 6, 2017 06:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndrewWeston9/9fabc5c173522395b0ea3a6f6babf9a2 to your computer and use it in GitHub Desktop.
Save AndrewWeston9/9fabc5c173522395b0ea3a6f6babf9a2 to your computer and use it in GitHub Desktop.
WorldManager.cs Snippet: Retrieving block health, updating block health, deleting a block.
public int getBlockHealth (int x, int y, int z)
{
if ((x >= 0) && (x < blockSize) &&
(y >= 0) && (y < blockSize) &&
(z >= 0) && (z < MaxBlockHeight))
{
return blockStructure[getIndex (x, y, z)].brickHealth;
}
return 0;
}
public void updateBlockHealth(int x, int y, int z, int amount)
{
if ((x >= 0) && (x < blockSize) &&
(y >= 0) && (y < blockSize) &&
(z >= 0) && (z < MaxBlockHeight))
{
blockStructure[getIndex (x, y, z)].brickHealth = blockStructure[getIndex (x, y, z)].brickHealth + amount;
//Debug.LogError ("updating block health");
}
}
public void deleteBlock(int x, int y, int z)
{
if ((x >= 0) && (x < blockSize) &&
(y >= 0) && (y < blockSize) &&
(z >= 0) && (z < MaxBlockHeight))
{
blockStructure[getIndex (x, y, z)].brickType = 0;
blockStructure[getIndex (x, y, z)].brickHealth = 0;
blockStructure[getIndex (x, y, z)].playerConnectionId = 0;
}
updateTimeStamp ();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment