I am trying to get whether or not there is grass on a given location on the terrain. I did a test of GetDetailLayer() comparing a 2500x2500 patch underneath an object on top of grass and one with no grass and in both cases the entire 2D array returned is filled with 0s. If this is the correct behavior for this call (which makes no sense to me given that I’m STARING at the grass under the grass objects) then any idea on how I can get this information from the terrain?
void Start () {
int[,] retVal;
Terrain myTerrain;
TerrainData myTData;
int xPos = (int)this.transform.position.x;
int zPos = (int)this.transform.position.z;
int xDir = 2500;
int zDir = 2500;
int found = 0;
myTerrain = (Terrain)FindObjectOfType(typeof(Terrain));
Debug.Log("terrain name " + myTerrain.name);
myTData = myTerrain.terrainData;
retVal = myTData.GetDetailLayer (xPos, zPos, xDir, zDir, 0);
Debug.Log("has decal " + this.name + " x:x " + this.transform.position.x + ":" + xPos + " z:z " + this.transform.position.z + ":" + zPos);
for(int i = 0; i < xDir; i++)
{
for(int j = 0; j < zDir; j++)
{
if( retVal[i,j] != 0 )
{
found++;
Debug.Log(i + "," + j + " " + retVal[i,j]);
}
}
}
Debug.Log("found = " + found);
}