Instantiate prefab freeze Unity

Hi everyone,

I have a pretty simple setup to destroy a crate and I encounter a problem quite randomly. When I destroy a crate everything works fine; when I have 2 or 3 crates close to each other and hit one, it instantiates as many instances that the editor freezes.

Here's is the crate code I use :

    var Wreck : GameObject;

    function OnCollisionEnter(collision : Collision) {

var contact : ContactPoint = collision.contacts[0];
Instantiate (Wreck, transform.position, transform.rotation);

Destroy (gameObject);
    }

and here is the rather simple weapon code:

var projectile : Rigidbody;

function Update () {

if (Input.GetButtonDown("Fire1")) {

    var clone : Rigidbody;
    clone = Instantiate(projectile, transform.position, transform.rotation);      
    clone.velocity = transform.TransformDirection (Vector3.forward * 40);

 }
}

Thanks in advance for your help!

I don't see anywhere in your code that you determine that the colliding object is the projectile. So the wreck you instatiate will collide with the crate (if your wrecks have a collider) spawning even more wrecks (since the crate doesn't get destroyed until after Update() is complete). Tag your projectile, then check your collision for that tag before you spawn "wreck", and see if that helps...