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 checkRigidBodySpeed() { foreach (Rigidbody RigidB in GameObject.FindObjectsOfType(typeof(Rigidbody))) { rbSpeed = Vector3.Distance(new Vector3(0, 0, 0), RigidB.velocity); if (rbSpeed < 0.2f) { RigidB.Sleep(); } } }
IEnumerator wallLayerSleep() { foreach (Rigidbody RigidB in GameObject.FindObjectsOfType(typeof(Rigidbody))) { if (RigidB.gameObject.tag.Contains("WallLayer")) { RigidB.name = RigidB.GetInstanceID().ToString(); RigidB.Sleep(); } } yield return(null); }
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; } } }
void Awake() { // CancelInvoke ("rigidBodySleep"); Time.timeScale = 0; this.GetComponent <AudioSource>().volume = 1; defaultHitSound.GetComponent <AudioSource>().volume = 1; foreach (Rigidbody RigidB in GameObject.FindObjectsOfType(typeof(Rigidbody))) { if (RigidB.gameObject.tag.Contains("WallLayer")) { RigidB.name = RigidB.GetInstanceID().ToString(); RigidB.Sleep(); RigidB.gameObject.GetComponent <AudioSource>().volume = 1; RigidB.gameObject.GetComponent <AudioSource>().rolloffMode = AudioRolloffMode.Linear; } } Time.timeScale = 1; }