Destroy OTHER objects on Collision Unity

I found a BUNCH of questions and comments about destroying an object if it is hit by something but in my scene, I want the PROJECTILE to be destroyed. How do I make it that anything that collides with an object gets destroyed? It’s sorta like a reverse bullet. c# please

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);
    }

For a collision to register, the following needs to be true:

  1. The objects needs a non-kinematic rigidbody and a non-trigger collider.
  2. The other object needs a non-trigger collider.
  3. One of the colliders needs to be convex.
  4. Both objects needs to be in layers that are set up to register collision (project settings → physics).

For a Trigger Collision to register, the other object needs a convex collider set to IsTrigger = true. Note that Addyarb posted an example that uses OnTriggerEnter. For a normal collision, you would use OnCollisionEnter():

void OnCollisionEnter(Collision collision){
         Destroy(collision.collider.gameObject);
         Destroy(gameObject);
         }

Bonus tip: Insert Debug.Log lines to see which parts of your code are called.

to make the OTHER destroying stuff you told copy this code:

public Transform gameobject;
void OnCollisionEnter(Collision coll) {
if (coll.gameobject.name == mycube) {
Destroy (gameobject);
}
}

Untiy has a great tutorial in one of their Learn courses:

Lesson 2.4 - Collision Decisions - Unity Learn

  1. Add a rigid body component and a collider to the projectile
  2. Add a collider to the thing you want to hit
    2.1 Check the box that says “Is Trigger” for both game objects
  3. Add this script to both game objects:

void OnTriggerEnter(Collider other)
{
Destroy(gameObject);
Destroy(other.gameObject);
}