On Collide Destroy Game Object

Hi. this is a simple question. but id like a script that made it so when a collided with a certan game object it will delete it from the level.

Thanks!!! Post a script.

var certainGameObjectName : String = "Bob";

function OnCollisionStart(collision : Collision)
    if (collision.gameObject.name == certainGameObjectName)
        Destroy(collision.gameObject); // destroys the thing this script bumped into


var explosionPrefab : Transform;

function OnCollisionEnter(collision : Collision) { // Rotate the object so that the y-axis faces along the normal of the surface var contact : ContactPoint = collision.contacts[0]; var rot : Quaternion = Quaternion.FromToRotation(Vector3.up, contact.normal); var pos : Vector3 = contact.point; Instantiate(explosionPrefab, pos, rot); // Destroy the projectile Destroy (gameObject); } function Update () { }

then put your explosion prefab in, (save the script then click and drag your explosion onto the empty slot) if you do not have an explosion prefab you can download 1 free of the unity website, link below :)


this is great, it gives you loads of explosion prefabs (if u want 2 publish i think they have copyright though, not sure look into it)