The bombs are instantiated and get destroyed on contact and produce a nice effect, but the last bit of the code doesn’t get executed after the bomb with the attached script is destroyed. This leaves a bunch of particle systems in the Hierarchy after dropping bombs everywhere. How can I fix this?
#pragma strict
var explosionPrefab : GameObject;
var explosionDebrisPrefab : GameObject;
var explosionBasePrefab : GameObject;
var clone:GameObject; // initiate GameObjects
var clone1:GameObject;
var clone2:GameObject;
var clone3:GameObject;
var clone4:GameObject;
var clone5:GameObject;
public 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;
clone = Instantiate(explosionPrefab, pos, Random.rotation);
clone1 = Instantiate(explosionDebrisPrefab, pos, Random.rotation);
clone2 = Instantiate(explosionDebrisPrefab, pos, Random.rotation);
clone3 = Instantiate(explosionDebrisPrefab, pos, Random.rotation);
clone4 = Instantiate(explosionDebrisPrefab, pos, Random.rotation);
clone5 = Instantiate(explosionBasePrefab, pos, rot);
Destroy(gameObject.FindWithTag("duplicateBomb"));
// Destroy the projectile effects
yield WaitForSeconds(3);
Destroy(clone);
Destroy(clone1);
Destroy(clone2);
Destroy(clone3);
Destroy(clone4);
Destroy(clone5);
}