Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to destroy OTHER game object on collision?

void OnCollisionEnter2D (Collision2D col){
    if (col.gameObject.tag == "Throwable") {
        Destroy (gameObject);
    }
}

This just destroys the gameobject who has script on it. But I want to destroy other object that collides with this object. Couldn't find the answer. I think there is an answer on unity3d(I assume from title) but somehow I can't connect the site. Also I tried them

Destroy (other.gameobject);
Destroy (gameObject.tag == "Throwable");

Didn't work anyways.

like image 361
klavyeadam Avatar asked Dec 05 '25 00:12

klavyeadam


1 Answers

void OnCollisionEnter2D (Collision2D col){
    if (col.gameObject.tag == "Throwable") {
        Destroy (col.gameObject);
    }
}

where col.gameObject it the incoming GameObject involved in the collision.

like image 102
Hellium Avatar answered Dec 07 '25 15:12

Hellium