public static int GetMask (params string[] layerNames);

参数

layerNames要转换为层遮罩的层名称的列表。

返回

intlayerNames 创建的层遮罩。

描述

给定在 Tags and Layers manager 中由 Builtin 或 User Layer 定义的一组层名称,返回所有这些层名称的等效层遮罩。

using UnityEngine;

public class Example : MonoBehaviour { void Start() { Debug.Log(LayerMask.GetMask("UserLayerA", "UserLayerB")); } }

注意:假设 UserLayerAUserLayerB 是第十层和第十一层。 这两个层会具有 User Layer 值 10 和 11。若要获取其层遮罩值, 可以将其名称传入 GetMask。参数可以是 其名称的列表或是存储其名称的字符串数组。在此例中, 返回值将为 2^10 + 2^11 = 3072。

Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961