Created
February 23, 2024 12:29
-
-
Save hman278/0ec52dc53a2702603351105805c6b577 to your computer and use it in GitHub Desktop.
Get the most dominant terrain layer at a certain position
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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