private void DestroyWithoutLookingForParent(GameObject toDestroy, bool useExplosion) { var allChilldren = FindImediateChildren(toDestroy); foreach (var child in allChilldren) { if (KillCompletely) { DestroyWithoutLookingForParent(child.gameObject, false); } else { child.SendMessage("Deactivate", SendMessageOptions.DontRequireReceiver); var rigidbody = child.GetComponent("Rigidbody") as Rigidbody; child.parent = null; if (UntagChildren) { //Debug.Log("untagging " + child); child.tag = DeadObjectTag; } if (rigidbody != null) { //Debug.Log("Severing " + rigidbody.name); rigidbody.angularDrag = 0; var fixedJoint = child.GetComponent("FixedJoint") as FixedJoint; if (fixedJoint != null) { UnityEngine.Object.Destroy(fixedJoint); } var hingeJoint = child.GetComponent("HingeJoint") as HingeJoint; if (hingeJoint != null) { UnityEngine.Object.Destroy(fixedJoint); } if (fixedJoint == null && hingeJoint == null) { //destroy anything that wasnt jointed to this object. DestroyWithoutLookingForParent(child.gameObject, false); } } else { DestroyWithoutLookingForParent(child.gameObject, false); } } } if (useExplosion && Exploder != null) { var rigidBodyToExplode = toDestroy.GetComponent <Rigidbody>(); Exploder.SetExplodingObject(rigidBodyToExplode); Exploder.ExplodeNow(); } GameObject.Destroy(toDestroy); }
private void DestroyWithoutLookingForParent(GameObject toDestroy, bool useExplosion, Vector3?velocityOverride) { var allChilldren = FindImediateChildren(toDestroy); foreach (var child in allChilldren) { child.SendMessage("Deactivate", SendMessageOptions.DontRequireReceiver); if (KillCompletely) { DestroyWithoutLookingForParent(child.gameObject, false, velocityOverride); } else { var rigidbody = child.GetComponent <Rigidbody>(); child.parent = null; if (rigidbody != null) { //Debug.Log("Severing " + rigidbody.name); rigidbody.angularDrag = 0; var fixedJoint = child.GetComponent <FixedJoint>(); if (fixedJoint != null) { Object.Destroy(fixedJoint); } var hingeJoint = child.GetComponent <HingeJoint>(); if (hingeJoint != null) { Object.Destroy(fixedJoint); } if (fixedJoint == null && hingeJoint == null) { //destroy anything that wasnt jointed to this object. DestroyWithoutLookingForParent(child.gameObject, false, velocityOverride); } } else { DestroyWithoutLookingForParent(child.gameObject, false, velocityOverride); } } } if (useExplosion && Exploder != null) { var rigidBodyToExplode = toDestroy.GetComponent <Rigidbody>(); Exploder.SetExplodingObject(rigidBodyToExplode); Exploder.ExplodeNow(velocityOverride); } toDestroy.transform.SendMessage("DieNow", SendMessageOptions.DontRequireReceiver); GameObject.Destroy(toDestroy); }
public void DetonateNow() { _exploder.ExplodeNow(); }