- Home /
Problem is not reproducible or outdated
A question for someone who understands alphamaps.
I'm trying to texture my terrain based on elevation. What am I missing/doing wrong? SORRY FOR HOW WEIRD THIS CODE LOOKS. Here's my code:
public Terrain yoTerrain;
void Start() {
alphaData = yoTerrain.terrainData.GetAlphamaps(0, 0, yoTerrain.terrainData.alphamapWidth, yoTerrain.terrainData.alphamapHeight);
for (int y = 0; y < yoTerrain.terrainData.alphamapHeight; y++)
{
for (int x = 0; x < yoTerrain.terrainData.alphamapWidth; x++)
{
float height = yoTerrain.terrainData.GetHeight(x, y);
if (height > 15){
alphaData[x, y, 0] = 0;
alphaData[x, y, 1] = 100;
}
if (height <= 15){
alphaData[x, y, 0] = 100;
alphaData[x, y, 1] = 0;
}
}
}
Now, my assumption would be that anywhere that the terrain's elevation is higher than 15, it would use texture "1" and if it was lower it would use texture "0". However, it's just putting random splotches everywhere. It seems like it's at least getting some sort of heights, but they're just way off. I tried mirroring it but it still seems random. What am I doing wrong?
I would gladly elaborate and specify if it's necessary. I have googled this to the best of my ability but the cold, clammy teachings of google fly over my head like the noble osprey.