| Parameter | Description |
|---|---|
| layerNames | The layer names (case sensitive) to find a combined physics mask for. |
PhysicsMask The combined physics mask for the layer names that were found. Unity produces a console warning for each layer name that isn't found and leaves it out of the mask, so if no names are found, PhysicsMask.None is returned.
Get a PhysicsMask for the specified layer name(s).
Use this method to build the category and contact masks for a ContactFilter so a shape only collides with the layers it needs to. Create the layers in a PhysicsCoreSettings2D asset first. When physics layers are active and more than one layer has the same name, the mask includes every layer with that name.
// Get a physics mask for a single layer, and another for a group of layers // that the object should collide with. using UnityEngine; using Unity.U2D.Physics;
public class GetLayerMaskExample : MonoBehaviour { void Start() { PhysicsMask objectLayer = PhysicsLayers.GetLayerMask("Car"); PhysicsMask contactLayer = PhysicsLayers.GetLayerMask("Walls"); } }