I have TNT that has an explosion script attached to it. I want it so that my TNT only explodes when it collides with my stockcar rather than other objects like the ground as well. I think I would usually know how to do this using tags but I used a script from a tutorial and am not sure how to put it in. I would also like to know how I would change the script so the sound plays only when the object collides with the stockcarHere is my entire script. Thanks,
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.gameObject.name == "Stockcar") {
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){
AudioSource.PlayClipAtPoint(sound, transform.position, soundVolume);
// stop emitting ?
if (particleEmitter) {
particleEmitter.emit = true;
yield WaitForSeconds(0.5);
particleEmitter.emit = false;
}
}
}