Object only explodes when it collides with certain object, not all rigidbodies.

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;

}

   }
   }

You will need to run through the list first and check the tag or the name. Untested example code:

var foundCar = false;

for (var hit in colliders) {
    if (hit.name == "Car") {
        foundCar = true;
        break;
     }
}
if (!foundCar) return;

Replace “Car” with whatever you’ve name your car(s). Note you are currently only making the check once (in Start()). You need to either put it in Update(), or make it a function and call using InvokeRepeating(). Or make it a coroutine.

Just needed this:
if (collision.gameObject.name == “Stockcar”)