void Start() { float weight; if (ExplosionSound) { this.GetComponent <AudioSource>().clip = ExplosionSound; } foreach (Rigidbody RigidB in GameObject.FindObjectsOfType(typeof(Rigidbody))) { BoxCollider Box = RigidB.GetComponent <BoxCollider> (); RigidB.name = RigidB.GetInstanceID().ToString(); RigidB.Sleep(); Box.size = Box.size / 1.5f; weight = Box.size.x + Box.size.y + Box.size.z; if (weight == 0) { Destroy(RigidB); } else { RigidB.GetComponent <Rigidbody>().mass = weight * 10.0f; } } InvokeRepeating("checkRigidBodySpeed", 0.5f, 1.0f); }
void OnEnable() { foreach (Rigidbody RigidB in this.transform.GetComponentsInChildren(typeof(Rigidbody))) { BoxCollider Box = RigidB.GetComponent <BoxCollider> (); RigidB.name = RigidB.GetInstanceID().ToString(); RigidB.Sleep(); Box.size = Box.size / 1.5f; float weight = Box.size.x + Box.size.y + Box.size.z; if (weight == 0) { Destroy(RigidB); } else { RigidB.GetComponent <Rigidbody>().mass = weight * 50.0f; } } }