Search code examples
c#unity-game-enginecollision

Layer for collision of rigid body


I am trying to define a layer for my rigidbody to ignore collision only from this layer. Can the layer to be ignored be named through script?

Current:

rb = GetComponent<Rigidbody>();
Physics.IgnoreLayerCollision(0, 11); //Layer number 11 = "Ignore Collision"

Target:

Physics.IgnoreLayerCollision("Ignore Collision"); //Layer number 11 = "Ignore Collision"

Solution

  • You can use LayerMask.NameToLayer

    Physics.IgnoreLayerCollision(LayerMask.NeToLayer("Default"), LayerMask.NameToLayer("Ignore Collision"));