[英]How to make a 2D collider collide only with a specific GameObject without using layers?
Suppose I have a BoxCollider2D in my player GameObject and I want it to ignore all other colliders, except another BoxCollider2D within an item.假设我的玩家游戏对象中有一个 BoxCollider2D,我希望它忽略所有其他碰撞器,项目中的另一个 BoxCollider2D 除外。
All of them are in the same layer and the layer collides with itself.它们都在同一层中,并且该层与自身发生碰撞。
I know that there is the Physics2D.IgnoreCollision
method, but is there a way to ignore ALL collisions except the collider of this item GameObject, that is in the same layer than the players?我知道有Physics2D.IgnoreCollision
方法,但是有没有办法忽略除此项目 GameObject 的对撞机之外的所有碰撞,即与玩家在同一层?
In a 2D game you can use the depth to avoid collision if you don't want to use layers.在 2D 游戏中,如果您不想使用图层,可以使用深度来避免碰撞。 For example, you can have all the objects that are part of the collision at z=0 and all that needs to avoid collision will be at z=1.例如,您可以在 z=0 处拥有属于碰撞一部分的所有对象,而所有需要避免碰撞的对象都位于 z=1 处。 Since its a 2D game there won't be any difference in what the camera renders.由于它是 2D 游戏,因此相机渲染的内容不会有任何差异。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.