- Home /
Question by
powerlol2807 · May 09 at 11:53 PM ·
terraintextureterrain generation
Cant change maptexture correctly in runtime
I wrote a code to change my texture with height of the terrain, but everytime I run it it this happens:
and my code looks like this:
void PaintTerrain()
{
float[,,] splatmapData = new float[terrain.terrainData.alphamapHeight,
terrain.terrainData.alphamapWidth,
terrain.terrainData.alphamapLayers];
for (int y = 0; y < terrain.terrainData.alphamapHeight; y++)
{
for (int x = 0; x < terrain.terrainData.alphamapWidth; x++)
{
float terrHeight = terrain.terrainData.GetHeight(y, x);
for (int h = 0; h < splatHeights.Length; h++)
{
if ( h == splatHeights.Length-1 &&terrHeight >= splatHeights[h].startHeight)
{
splatmapData[y, x, h] = 1;
}
else
if ( terrHeight >= splatHeights[h].startHeight && terrHeight <= splatHeights[h+1].startHeight)
{
splatmapData[y, x, h] = 1;
}
}
}
}
terrain.terrainData.SetAlphamaps(0, 0, splatmapData);
}
after seaching for a solution for 4 hours now I am just tired and I am in need of help.
Comment