可将 Tilemap Collider 2D 组件添加到 Tilemap 游戏对象来为相应 Tilemap 组件中设置的每个__瓦片 (Tile)__ 生成__碰撞体 (Collider)__ 形状。在 Tilemap 组件中添加或删除瓦片时,Tilemap Collider 2D 组件会在 LateUpdate
期间更新碰撞体形状。
为 Tilemap 组件中的每个瓦片生成的碰撞体形状取决于瓦片资源中设置的所需碰撞体类型。
Collider Type | 功能 |
---|---|
None | Tilemap Collider 2D 组件不会为此瓦片生成任何碰撞体形状。 |
Sprite | Tilemap Collider 2D 组件基于分配给瓦片的精灵生成碰撞体形状。碰撞体形状可以是为精灵设置的自定义物理形状,也可以是从精灵轮廓生成的近似形状。 |
Grid | Tilemap Collider 2D 组件基于网格单元格的形状(由 Grid 组件的选定单元格布局 (Cell Layout) 确定)生成碰撞体形状。 |
此碰撞体与 Composite Collider 2D 组件结合使用。要将相邻瓦片的碰撞体形状合成在一起,请将两者添加到同一 Tilemap 组件。这样可以平滑相邻瓦片中碰撞体形状之间的角和边。
这样做还可以提高 Tilemap Collider 的性能,因为物理更新中涉及的单独碰撞体形状更少。如此将减少所需的计算量。
属性 | 功能 |
---|---|
Material | 一种物理材质,可用于确定碰撞的属性(例如摩擦和弹性)。 |
Is Trigger | 选中此复选框可使 Tilemap Collider 2D 组件作为触发器运行。 |
Used by Composite | 选中此复选框可使此碰撞体由附加的 Composite Collider 2D 组件使用。 当启用 Used by Composite 时,除了 Offset 之外的所有属性在 Tilemap Collider 2D 组件中都不再可用。相反,这些属性由附加的 Composite Collider 2D 组件控制。 |
Used by Effector | 选中此复选框可使 Tilemap Collider 2D 组件由附加的 Effectors 2D 组件使用。 |
Offset | Tilemap Collider 2D 几何形状的局部偏移。 |
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.