Delete collider object object in unity 3d

Here is my code in the Update function. 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 destroyed.

How can I destroy him?

+4
source share
2 answers

Now it works with code

  Destroy(hit3.collider); 
+3
source

According to the Destroy () docs, "The actual destruction of an object is always delayed until the current update cycle, but will always be done before rendering."

Could this be a problem? If you check inside the current update function, the object has not yet been destroyed. Otherwise, Destroy () must remove all components of this GameObject.

+1
source

All Articles