简体   繁体   English

如何在Unity中检测Tilemap碰撞体和2D盒子碰撞体之间的碰撞

[英]How can I detect collisions between Tilemap Colliders and 2D box colliders in Unity

I've run into a bit of a problem in my developing of a Unity2D game. 我在开发Unity2D游戏时遇到了一个问题。

I'm trying to have bullets be destroyed when they hit a part of a tile map I created. 我试图让子弹碰到我创建的图块地图的一部分时将其销毁。 When a bullet and a tile map collide, the "OnCollisionEnter2D()" function doesn't read the collision. 当项目符号和图块地图碰撞时,“ OnCollisionEnter2D()”函数不会读取碰撞。 It does read the collision between sprites and other sprites however. 但是,它确实读取了子画面和其他子画面之间的碰撞。 But not between a sprite and a tile map. 但不在精灵和图块地图之间。

I've checked and both objects have the appropriate collider components (Box Collider 2D and Tilemap Collider 2D) and they also have their scripts attached. 我已经检查了两个对象是否具有合适的对撞机组件(Box Collider 2D和Tilemap Collider 2D),并且还附加了脚本。

Can somebody suggest a solution of tell me what I'm doing wrong? 有人可以建议告诉我我在做什么错的解决方案吗?

Thanks in advance, Maiko vd Veen. 在此先感谢Maiko vd Veen。

Have you checked if the bullet collider is marked as a trigger? 您是否检查了子弹对撞机是否被标记为触发器? In that case, use OnTriggerEnter2D() . 在这种情况下,请使用OnTriggerEnter2D()

您的子弹需要用刚体2D来触发对撞机之间的碰撞。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM