You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

37 lines
1.1 KiB

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace UnityStandardAssets.Effects
{
public class ExplosionPhysicsForce : MonoBehaviour
{
public float explosionForce = 4;
private IEnumerator Start()
{
// wait one frame because some explosions instantiate debris which should then
// be pushed by physics force
yield return null;
float multiplier = GetComponent<ParticleSystemMultiplier>().multiplier;
float r = 10*multiplier;
var cols = Physics.OverlapSphere(transform.position, r);
var rigidbodies = new List<Rigidbody>();
foreach (var col in cols)
{
if (col.attachedRigidbody != null && !rigidbodies.Contains(col.attachedRigidbody))
{
rigidbodies.Add(col.attachedRigidbody);
}
}
foreach (var rb in rigidbodies)
{
rb.AddExplosionForce(explosionForce*multiplier, transform.position, r, 1*multiplier, ForceMode.Impulse);
}
}
}
}