/// <summary> /// Creates fragments if necessary and destroys original gameobject /// </summary> public void explode() { //if fragments were not created before runtime then create them now if (fragments.Count == 0 && allowRuntimeFragmentation) { generateFragments(); } //otherwise unparent and activate them else { foreach (GameObject frag in fragments) { FadeOut fo = frag.GetComponent <FadeOut>(); fo.Prepare(); } } //if fragments exist destroy the original if (fragments.Count > 0) { //gameObject.transform.position = pos; gameObject.GetComponent <Renderer>().enabled = false; gameObject.GetComponent <Rigidbody2D>().simulated = false; exploding = true; explosionAudioSource.Play(); Invoke("resetMe", 3); } }