how to destroy spawn objects in collision in unity code example
Example 1: unity3d on collision destroy object
Here's both ways to destroy the gameObject, or the gameObject you collide with.
void OnTriggerEnter(Collider col){
Destroy(col. gameObject);
}
void OnTriggerEnter(){
Destroy(gameObject);
}
Example 2: unity destroy object on collision
void OnCollisionEnter2D(Collision2D coll)
}
// Check if we have collided with the enemy
if (coll.gameObject.tag == "Enemy")
{
Destroy(coll.gameObject);
}
}