我想在实例化之前检查我的 Prefeb 是否与游戏对象重叠。请注意,预制件的大小和形式各不相同。
我已经尝试了很多方法并在谷歌上搜索了很多东西,但我无法让它工作。我什至通过询问 ChatGPT 而犯了罪(它没有产生任何好的结果,因为它当然没有)。谁能给我一些代码片段?
我建议使用 Physics.Overlap 函数,假设您的预制对象上的碰撞器本质上更简单。
例如:
public bool TestOverLapCircle(Vector2 point, CircleCollider2D prefabCollider)
{
//get the overlap colliders with the radius of the CircleCollider multiplied by the scale
Collider2D hitCollider = Physics2D.OverlapCircle(point, prefabCollider.radius * prefabCollider.transform.lossyScale.x);
return hitCollider != null;
}