Class LayerExtensions
Provides extension methods for working with Unity LayerMasks and layers.
public static class LayerExtensions
Inheritance
Methods
Contains(LayerMask, int)
Determines whether a specific layer is included in the given LayerMask.
public static bool Contains(this LayerMask mask, int layer)
Parameters
| Name | Type | Description |
|---|---|---|
mask | LayerMask | The LayerMask to check against. |
layer | int | The layer number (0–31) to check for inclusion. |
Returns
bool — True if the layer is included in the mask; otherwise, false.
GetLayerCollisionMask(int)
Generates a LayerMask containing all layers that can collide with the specified layer. This version takes a single layer represented as an integer.
public static LayerMask GetLayerCollisionMask(this int layers)
Parameters
| Name | Type | Description |
|---|---|---|
layers | int | The target layer as an integer (0–31) for which to find collidable layers. |
Returns
LayerMask — A LayerMask including all layers that the specified layer can collide with based on the current Physics settings.
GetLayerCollisionMask(LayerMask)
Generates a LayerMask containing all layers that can collide with the layers specified in the given LayerMask. This version takes a LayerMask and evaluates each layer within it.
public static LayerMask GetLayerCollisionMask(this LayerMask layers)
Parameters
| Name | Type | Description |
|---|---|---|
layers | LayerMask | A LayerMask representing one or more layers for which to find collidable layers. |
Returns
LayerMask — A new LayerMask including all layers that can collide with any of the layers in the specified LayerMask, based on the current Physics collision matrix.