using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestLayer : MonoBehaviour
{
void Start()
{
string layerName = "TestLayer";
TagManagerAutoAdd.AutoAddLayer(layerName);
this.gameObject.layer = LayerMask.NameToLayer(layerName);
Debug.Log(LayerMask.NameToLayer(layerName));
Debug.Log(this.gameObject.layer);
//print(SortingLayer.GetLayerValueFromName(layerName));
Camera.main.cullingMask &= ~(1 << this.gameObject.layer);
}
}
参考资料1,2里面的
using UnityEditor;
using UnityEngine;
...
public class TagManagerAutoAdd//类的名字 与脚本的文件名称一致
...
public static void AutoAddLayer(string layer)//改为static void AutoAddLayer(string layer)
...
运行结束的时候,添加的Layer的名字会清空。
貌似只能在 Unity编辑器里面使用,不能在打包后进行使用。