I am having trouble understanding the SetAlphamaps usage, I currently have a script that changes the texture of the terrain surrounding an object. see bellow;
public Terrain myTerrain;
private TerrainData myTerrainData;
public GameObject test;
public int ranage = 1;
void Start ()
{
myTerrainData = myTerrain.terrainData;
int mapx = (int)(((test.transform.position.x - myTerrain.transform.position.x) / myTerrainData.size.x) * myTerrainData.alphamapWidth);
int mapz = (int)(((test.transform.position.z - myTerrain.transform.position.z) / myTerrainData.size.z) * myTerrainData.alphamapHeight);
float[,,] map = new float[myTerrainData.alphamapWidth, myTerrainData.alphamapHeight, 3];
for (int y = mapx - ranage; y < mapx + ranage; y++)
{
for (int x = mapz - ranage; x < mapz + ranage; x++)
{
map[x, y, 0] = 0;
map[x, y, 1] = 1;
}
}
myTerrainData.SetAlphamaps(0, 0, map);
}
result:
I would like this code to leave all the black zone as the default texture, even better would be to only change the yellow zone and not compute the rest of the terrain for efficiency sake. I have red the unit docs but its rather small and not understandable.
Any help or pointing in the right direction would be a massive help, thank you!