# SLayerMask

**成员** 6

|      |                             |                                                   |
| ---- | --------------------------- | ------------------------------------------------- |
| 函数 | [SetLayers](#setlayers)     | \_Function that changes an existing layer mask \_ |
| 函数 | [AddLayer](#addlayer)       | Add a new layer to an existing layer mask.        |
| 函数 | [RemoveLayer](#removelayer) | Remove a new layer from an existing layer mask.   |
| 函数 | [New](#new)                 | Static function that creates a new layer mask     |
| 属性 | [Inverted](#inverted)       | Is the mask exclusionary or not.                  |
| 属性 | [Layers](#layers)           | The layer names represented in this layer mask    |

## 函数

### SetLayers

void SetLayers(params string\[] layerNames)

void SetLayers(Table layerNames)

\_Function that changes an existing layer mask \_

参数

| 名称       | 类型             | 默认值 |
| ---------- | ---------------- | ------ |
| layerNames | params string\[] | –      |
| layerNames | Table            | –      |

返回值

`void`

示例

**Lua**

```lua
-- Let's create a new layer mask to filter out other avatars, then overwrite it to be vehicles instead:
local mask = LayerMask.New({"Avatars"});
mask.SetLayers({"Vehicles"});
local hit = Space.Physics.RaycastSingle(Space.Host.ExecutingObject.WorldPosition, Space.Host.ExecutingObject.Forward, 500.0, mask)

```

**Lua**

```lua
-- Let's create a new layer mask to filter out other avatars, then overwrite it to be vehicles instead:
local mask = LayerMask.New("Avatars");
mask.SetLayers("Vehicles");
local hit = Space.Physics.RaycastSingle(Space.Host.ExecutingObject.WorldPosition, Space.Host.ExecutingObject.Forward, 500.0, mask)

```

### AddLayer

void AddLayer(string layerName)

Add a new layer to an existing layer mask.

参数

| 名称      | 类型   | 默认值 |
| --------- | ------ | ------ |
| layerName | string | –      |

返回值

`void`

示例

**Lua**

```lua
local mask = LayerMask.New("Avatars");
mask.AddLayer("Vehicles");
local hit = Space.Physics.RaycastSingle(Space.Host.ExecutingObject.WorldPosition, Space.Host.ExecutingObject.Forward, 500.0, mask)

```

**Lua**

```lua
local mask = LayerMask.New("Avatars");
mask.AddLayer("Vehicles");
local hit = Space.Physics.RaycastSingle(Space.Host.ExecutingObject.WorldPosition, Space.Host.ExecutingObject.Forward, 500.0, mask)

```

### RemoveLayer

void RemoveLayer(string layerName)

Remove a new layer from an existing layer mask.

参数

| 名称      | 类型   | 默认值 |
| --------- | ------ | ------ |
| layerName | string | –      |

返回值

`void`

示例

**Lua**

```lua
local mask = LayerMask.New("Avatars", "Vehicles", "UI");
mask.RemoveLayer("Vehicles");
local hit = Space.Physics.RaycastSingle(Space.Host.ExecutingObject.WorldPosition, Space.Host.ExecutingObject.Forward, 500.0, mask)

```

**Lua**

```lua
local mask = LayerMask.New("Avatars", "Vehicles", "UI");
mask.RemoveLayer("Vehicles");
local hit = Space.Physics.RaycastSingle(Space.Host.ExecutingObject.WorldPosition, Space.Host.ExecutingObject.Forward, 500.0, mask)

```

### New

static SLayerMask New(Table layerNames)

static SLayerMask New(params string\[] layerNames)

Static function that creates a new layer mask

参数

| 名称       | 类型             | 默认值 |
| ---------- | ---------------- | ------ |
| layerNames | Table            | –      |
| layerNames | params string\[] | –      |

返回值

`SLayerMask`

示例

**Lua**

```lua
local mask = LayerMask.New({"Avatars", "Vehicles"});
local hit = Space.Physics.RaycastSingle(Space.Host.ExecutingObject.WorldPosition, Space.Host.ExecutingObject.Forward, 500.0, mask)

```

**Lua**

```lua
local mask = LayerMask.New("Avatars");
or
local mask = LayerMask.New("Avatars", "Vehicles", "UI");
local hit = Space.Physics.RaycastSingle(Space.Host.ExecutingObject.WorldPosition, Space.Host.ExecutingObject.Forward, 500.0, mask)

```

## 属性

### Inverted

bool Inverted {get; set; }

Is the mask exclusionary or not.

示例

**Lua**

```lua
local mask = LayerMask.New("Avatars");
-- Now change it to be an exclusionary mask that gets everything EXCEPT Avatars.'

mask.inverted = true;

```

### Layers

string\[] Layers {get; set; }

The layer names represented in this layer mask

示例

**Lua**

```lua
local mask = LayerMask.New("Avatars");
-- Get
local layers = mask.Layers;
-- Set
local layers = {"Vehicles", "UI"};

mask.Layers = layers;

```
