Skip to content

Instantly share code, notes, and snippets.

@hman278
Created February 23, 2024 12:29
Show Gist options
  • Save hman278/0ec52dc53a2702603351105805c6b577 to your computer and use it in GitHub Desktop.
Save hman278/0ec52dc53a2702603351105805c6b577 to your computer and use it in GitHub Desktop.
Get the most dominant terrain layer at a certain position
private void GetColorAtPosition(ref Vector2Int position)
{
float[,,] alphamaps = _terrainData.GetAlphamaps(position.x, position.y, 1, 1);
int dominantLayer = 0;
// Represents the most dense terrain layer applied at the supplied position
float maxDensity = 0f;
for (int i = 0; i < alphamaps.GetLength(2); ++i)
{
if (alphamaps[0, 0, i] > maxDensity)
{
maxDensity = alphamaps[0, 0, i];
dominantLayer = i;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment