i need function that goes through all the existing layer names and find if my layer is there and if not then the code need to add the given layer to the layer list
i tried this code this unity forum
void CreateLayer()
{
SerializedObject tagManager = new SerializedObject(AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/TagManager.asset")[0]);
SerializedProperty layers = tagManager.FindProperty("layers");
if (layers == null || !layers.isArray)
{
Debug.LogWarning("Can't set up the layers. It's possible the format of the layers and tags data has changed in this version of Unity.");
Debug.LogWarning("Layers is null: " + (layers == null));
return;
}
for (int i = 8; i < 31; i++)
{
SerializedProperty layerSP = layers.GetArrayElementAtIndex(i);
if (layerSP.stringValue == "MyLayer")
{
return;
}
}
for (int i = 8; i < 31; i++)
{
SerializedProperty layerSP = layers.GetArrayElementAtIndex(i);
if (layerSP.stringValue != "")
{
layerSP.stringValue = "MyLayer";
break;
}
}
tagManager.ApplyModifiedProperties();
}
but it dosen't work for me
by the way i'm using unity 5.6.3
if anybody knows the answer please share