刚体碰撞层

Layer for collision of rigid body

我正在尝试为我的刚体定义一个层以仅忽略来自该层的碰撞。可以通过脚本命名要忽略的层吗?

当前:

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

目标:

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

您可以使用LayerMask.NameToLayer

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