unity how to destroy obj code example
Example 1: unity destroy gameobject
// Destroy this gameobject
Destroy(gameObject);
// Kills the game object in 5 seconds
Destroy(gameObject, 5);
// Removes this script instance from the game object
Destroy(this);
// Removes the rigidbody from the game object
Destroy(GetComponent<Rigidbody>());
Example 2: how to destroy a gameobject after some hits in unity 3d
void OnCollisionEnter(Collision YourGameobjectasAVarable) { if(YourGameobjectasAVarable.collider.tag == "YourGameObject'sTag") { //Whatever you want to happen, in your case you want it to be destroyed Destroy(//Your game object//*) }