// Update is called once per frame void Update() { if (br == null) { fire.SetActive(true); RaycastHit hit; if (Physics.Raycast(fire.transform.position, fire.transform.forward, out hit, 1.5f)) { //Debug.DrawLine (fire.transform.position,fire.transform.position + (-fire.transform.up * 1.5f)); Fracture fract = hit.collider.gameObject.GetComponent <Fracture> (); Breakable breaka = hit.collider.gameObject.GetComponent <Breakable> (); if (fract != null) { fract.Break(0); } else if (breaka != null) { breaka.Break(0); } } } if (!dm.beingHeld && br == null) { rb.AddExplosionForce(18f, fire.transform.position, 2f); } }
void OnCollisionEnter(Collision coll) { if (rb.velocity.magnitude > 1f) { Collider[] colliders = Physics.OverlapSphere(transform.position, explosiveRadius); foreach (Collider hit in colliders) { Rigidbody rb = hit.GetComponent <Rigidbody>(); if (rb != null) { rb.AddExplosionForce(explosiveForce, transform.position, explosiveRadius, 3.0F); } Fracture fr = hit.GetComponent <Fracture> (); if (fr != null) { fr.Break(1); } Breakable br = hit.GetComponent <Breakable> (); if (br != null) { br.Break(1); } } //Spawn sound if (DestructionSounds.Capacity > 0) { AudioSource.PlayClipAtPoint(DestructionSounds[(int)Mathf.Round(Random.Range(0, DestructionSounds.Capacity - 1))], transform.position, 0.125f); } //Spawn the particles Instantiate(particles, transform.position, Quaternion.identity); Destroy(this.gameObject); } }