Skip to content

Instantly share code, notes, and snippets.

@AndrewWeston9
Last active October 6, 2017 06:43
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/3a682f177bd3e72eb629904970c9519f to your computer and use it in GitHub Desktop.
Save AndrewWeston9/3a682f177bd3e72eb629904970c9519f to your computer and use it in GitHub Desktop.
WorldManager.cs Snippet: Update Resource block levels by passing location and amount to adjust by.
/// Update a change of resource in the level structure.
public void updateResource(float x, float y, float z, int amount)
{
int rx = ((int) x) % blockSize;
int ry = ((int) y) % blockSize;
int rz = ((int) z);
RegionBlock rb = getRegion (x, y);
if (rb != null)
{
rb.updateBlockHealth (rx, ry, rz, amount);
int blockHealth = rb.getBlockHealth (rx, ry, rz);
//Debug.LogError ("Health of block: " + blockHealth.ToString ());
if (blockHealth < 1)
{
rb.deleteBlock(rx, ry, rz);
refreshMesh ();
}
}
refreshMesh ();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment