destroy an object unity code example

Example 1: unity remove gameobject

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

Example 2: 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 3: destroy gameobject unity

Destroy(this.gameObject);

Example 4: drop a object if destroy object unity

drop a object if destroy object unity

Example 5: how to destroy an object in unity

Destroy(gameObject);