unity collision code example
Example 1: how to do collision tag in unity
void OnColliSionEnter2D(Collision col){
if (col.gameobject.tag == "Enemy"){
Destroy(gameObject)
}
}
Example 2: unity 2d collision
void OnCollisionEnter2D(Collision2D col) {
Debug.Log("Collided with: " + col.gameObject.name);
}