- Home /
The question is answered, right answer was accepted
Terrain set detail layer problem.
Ok, so I have this terrain that cuts itself up and then places stuff on. This code I have places details on the terrain using the Terrain scripts detail prototypes. However it only places the first detail in the list. I cannot get it to place anything other than the first. The last integer at the end of GetDetailLayer is supposed to do it but, nothing shows up if I change it to above 1. Setting it to 1 still only shows the first detail. I'm very confused please help. It should be working, I don't get it.
void PlaceDetail(Terrain t, Vector3 pos, float radius)
{
int TerrainDetailMapSize = t.terrainData.detailResolution;
float pixelSize = TerrainDetailMapSize / t.terrainData.size.x;
Vector3 TexturePoint3D = pos - t.transform.position;
TexturePoint3D = TexturePoint3D * pixelSize;
float[] xymaxmin = new float[4];
xymaxmin[0] = TexturePoint3D.z + radius;
xymaxmin[1] = TexturePoint3D.z - radius;
xymaxmin[2] = TexturePoint3D.x + radius;
xymaxmin[3] = TexturePoint3D.x - radius;
int[,] map = t.terrainData.GetDetailLayer(0,0, t.terrainData.detailWidth, t.terrainData.detailHeight, 0);
for (int y = 0; y < t.terrainData.detailHeight; y++) {
if(xymaxmin[2] > y && xymaxmin[3] < y)
{
for (int x = 0; x < t.terrainData.detailWidth; x++) {
if(xymaxmin[0] > x && xymaxmin[1] < x)
map[x,y] = 1;
}
}
}
t.terrainData.SetDetailLayer(0,0,0,map);
t.Flush();
I think...
line 13 means "get all stuff on detailLayer 0" (that final 0 = detailLayer); if you wanted additional details you need 1,2,3...etc.
The same for SetDetailLayer, the 3rd "0" in (0,0,0...) is the Layer, if you want more details on additional layers, you need 0,0,1 0,0,2 etc.