The Custom Collider 2D is a Collider that interacts with the 2D physics system. Unlike other Colliders, you do not configure the Collider in-Editor, instead you configure the Collider by assigning PhysicsShape2D geometry to it via the PhysicsShapeGroup2D API. You can further define the Collider by adding, removing and modifying the PhysicsShape2D
shapes. Refer to the PhysicsShape2D API documentation for more information. This also means that a Custom Collider 2D can contain an unlimited number of low-level PhysicsShape2D
and represent any type of shape, or emulate other types of Collider 2D.
When assigning PhysicsShape2D
to the Custom Collider 2D, you can do so either during Edit mode or Play mode. When modifying the Custom Collider 2D in Edit mode, Unity saves all assigned PhysicsShape2D
and associated vertices in the Unity Scene, and the CustomCollider2D
retains its configuration when the Scene is loaded. This makes it possible to use Edit mode authoring scripts to create custom geometry.
When modifying the Custom Collider 2D during Play mode, the Collider will not retain any changes made to assigned PhysicsShape2D
and their associated vertices, and all changes will be lost when exiting Play mode.
属性 | 功能 |
---|---|
Density | Change the Density value to change the mass calculations of the GameObject’s associated Rigidbody 2D. If you set the value to 0, its associated Rigidbody 2D ignores the Collider 2D for all mass calculations, including center of mass calculations. Note: This property is only available when the Rigidbody 2D component attached to the GameObject has Use Auto Mass enabled. |
Material | 一种 2D 物理材质,可用于确定碰撞的属性(例如摩擦和弹性)。 |
Is Trigger | Enable this property if you want the Custom Collider 2D to behave as a trigger (refer to Colliders Overview for more information on using triggers). |
Used By Effector | Enable this property if you want the Custom Collider 2D to be used by an attached Effector 2D component. |
Offset | Set the local offset values of the Collider 2D geometry. |
Custom Shape Count (Read Only) | Indicates how many PhysicsShape2D the Collider is using. |
Custom Vertex Count (Read Only) | Indicates how many vertices all PhysicsShape2D in the Collider are using. |