How would i destroy self after collision?

I have tried many different strategies which have all failed, could someone please make a simple script that destroys the object it is attached to when it collides with ANY other object (not a specific object)

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

I think that works? Not sure. Will test when I can.
Make sure you spell everything right XD I remeber when I spelt Destroy Destory

Didn’t work, anything else you may have missed?

So the way the C# code I gave you before works is you need to have some object have “Is Trigger” Enabled on it’s Collider. then when it goes through the object it will delete it’s self. If you don’t want to add Is Trigger to everything here’s a different method.

void OnCollisionEnter(Collision other) {
        Destroy(gameObject);
}

neither of them worked
I have a 2D bullet, it has a collider which is a trigger, it also has the exact c# code you gave me, not working…

well then if it is 2D I think the proper code is :

void OnTriggerEnter2D (Collider2D other)
{
Destroy (gameObject)
}

give it a try

sorry I couldn’t reply, the unity forums refused to work, testing it out now!

it works, now how would I make it collide with only, lets say 2 different objects out of 4?

works! how would I make it so it collides with everything except for one thing now?

I would suggest you take a look at the Scripting Reference :slight_smile: