how to remove gameobject unity code example

Example 1: unity remove gameobject

// To remove a GameObject use the function 'Destroy()'
Destroy(gameObject);

Example 2: unity remove component in script

Destroy (gameObject);

Example 3: how to destroy a gameobject in c#

Destroy(gameObject); // destroys the game object attached to the script

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

void OnCollisionEnter(Collision other)  {      hit += 1;      checkhit();  }

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