简体   繁体   English

统一删除3d对象的Box collider

[英]Remove Box collider of object in unity 3d

Here is my code in Update function. 这是我在Update函数中的代码。 The object has a box collider. 该对象具有一个盒子碰撞器。

if (Input.GetMouseButtonDown(0)) { 
    Ray ray = camera.ScreenPointToRay(Input.mousePosition); 
    if (Physics.Raycast (ray, out hit3, 400.0F)) {
        wName = hit3.collider.gameObject.name;
        Destroy(hit3.collider.gameObject);
    }
}

But the box collider is not getting destroyed. 但是撞机盒并没有被摧毁。

How can I destroy it? 我该如何销毁它?

现在可以使用代码

 Destroy(hit3.collider);

According to the docs on Destroy() "Actual object destruction is always delayed until after the current Update loop, but will always be done before rendering." 根据Destroy()上的文档,“实际对象破坏总是延迟到当前Update循环之后,但总是会在渲染之前完成。”

Could this be the issue? 这可能是问题吗? If you check within the current Update function that object might not have been destroyed yet. 如果您在当前的Update函数中进行检查,则该对象可能尚未销毁。 Otherwise Destroy() should remove all the components of that GameObject. 否则,Destroy()应该删除该GameObject的所有组件。

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

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