1 using System;
2 using
System.Collections;
3 using
System.Collections.Generic;
4 using
UnityEngine;
5
6 namespace
UnityStandardAssets.Effects
7 {
8     
public class ExplosionPhysicsForce : MonoBehaviour
9     {
10         
public float explosionForce = 4;
11
12
13         
private IEnumerator Start()
14         {
15             
// wait one frame because some explosions instantiate debris which should then
16             
// be pushed by physics force
17             
yield return null;
18
19             
float multiplier = GetComponent<ParticleSystemMultiplier>().multiplier;
20
21             
float r = 10*multiplier;
22             
var cols = Physics.OverlapSphere(transform.position, r);
23             
var rigidbodies = new List<Rigidbody>();
24             
foreach (var col in cols)
25             {
26                 
if (col.attachedRigidbody != null && !rigidbodies.Contains(col.attachedRigidbody))
27                 {
28                     rigidbodies.Add(col.attachedRigidbody);
29                 }
30             }
31             
foreach (var rb in rigidbodies)
32             {
33                 rb.AddExplosionForce(explosionForce*multiplier, transform.position, r,
1*multiplier, ForceMode.Impulse);
34             }
35         }
36     }
37 }