Skip to content

Instantly share code, notes, and snippets.

@IronMonk-UK
Last active May 11, 2016 17:05
Show Gist options
  • Save IronMonk-UK/b4fb0895ac37016699e461929d9af013 to your computer and use it in GitHub Desktop.
Save IronMonk-UK/b4fb0895ac37016699e461929d9af013 to your computer and use it in GitHub Desktop.
// Method to add in forest tiles to the map
void AddForests() {
// A for loop is run, with i starting at 0, and increasing until it has reached a sixth
// of the total tiles, calculated by multiplying the X and Y map lengths, and dividing
// the result by 6
for (int i = 0; i < Mathf.RoundToInt((worldSize.x * worldSize.y) / 6); i++) {
// Random X and Y variables are generated
int x = Mathf.RoundToInt(Random.Range(0, worldSize.x));
int y = Mathf.RoundToInt(Random.Range(0, worldSize.y));
// If the forest bool of the tile attached to the node with the random
// X and Y position
if(!grid[x, y].tile.forest) {
// The forest bool on that tile is turned true
grid[x, y].tile.forest = true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment