Hi,
I have a runtima generated terrain like this:
public enum Layer
{
Terrain = 1 << 8,
Tower = 1 << 9,
Enemy = 1 << 10,
TowerBeingSet = 1 << 11,
PathEnd = 1 << 12
};
this.terrainData = new TerrainData ();
// terrainData init //
AssetDatabase.CreateAsset (terrainData, "Assets/New Terrain.asset");
this.terrainGameObject = Terrain.CreateTerrainGameObject (this.terrainData);
And then I try to set up the layer for it with:
this.terrainGameObject.layer = (int)Layer.Terrain;
foreach (Transform trans in terrainGameObject.GetComponentsInChildren<Transform>(true)) {
trans.gameObject.layer = (int)Layer.Terrain;
}
But when I run the scene the terrain go has its layer set to “Default” and all events that depend on the layer obviously doesn’t work.
So, what would be the right way to set a terrains layer?
Thx in advance.
Using
LayerMask.NameToLayer (“Terrain”);
instead of the shifted ints enum works fine.
terrainGameObject.gameObject.layer = LayerMask.NameToLayer(“LAYER_NAME”);