how to destroy a gameobject after time unity code example

Example 1: 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//*)         }

Example 2: how to destroy a gameobject after some hits in unity 3d

public int hit = 0; public GameObject brickParticle; public AudioClip Brick_breaking; void OnCollisionEnter(Collision other) {     hit += 1; } void checkhit() {     if (hit == 2)     {         AudioSource.PlayClipAtPoint(Brick_breaking, transform.position);         Instantiate(brickParticle, transform.position, Quaternion.identity);         GM.instance.DestroyBrick();         Destroy(gameObject);     } }