Hi thats modified version of a script from the fps tutorial.
Attach it to a particle system, spawn it when an object destoys itself ( rocket hit wall / barrel get shot )
It will do damage to the sourounding ( via the message apply damage)
But the Problem: It only checks for riggid bodies, it doesn’t work on the fps controler or a character controler. Any Ideas ???
var explosionRadius = 5.0;
var explosionPower = 10.0;
var explosionDamage = 100.0;
var explosionTime = 1.0;
var sound : AudioClip;
var soundVolume : float = 2.0;
function Start () {
var explosionPosition = transform.position;
var colliders : Collider[] = Physics.OverlapSphere (explosionPosition, explosionRadius);
for (var hit in colliders) {
if (!hit)
continue;
if (hit.rigidbody) {
hit.rigidbody.AddExplosionForce(explosionPower, explosionPosition, explosionRadius, 3.0);
var closestPoint = hit.rigidbody.ClosestPointOnBounds(explosionPosition);
var distance = Vector3.Distance(closestPoint, explosionPosition);
// The hit points we apply fall decrease with distance from the hit point
var hitPoints = 1.0 - Mathf.Clamp01(distance / explosionRadius);
hitPoints *= explosionDamage;
// Tell the rigidbody or any other script attached to the hit object
// how much damage is to be applied!
hit.rigidbody.SendMessageUpwards("ApplyDamage", hitPoints, SendMessageOptions.DontRequireReceiver);
}
}
if (sound) // ansonsten gehts hier weiter
AudioSource.PlayClipAtPoint(sound, transform.position, soundVolume);
// stop emitting ?
if (particleEmitter) {
particleEmitter.emit = true;
yield WaitForSeconds(0.5);
particleEmitter.emit = false;
}
// destroy the explosion
Destroy (gameObject, explosionTime);