How to instantiate prefab when colliding with specified prefab

Hello, so I want this script to instantiate a prefab when colliding with a specified prefab. Right now my script is spawning the prefab whenever the object is colliding with anything:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class explosion : MonoBehaviour
{
    public GameObject explosionPrefab;
    public float      explodeSecs = -1;

    void OnCollisionEnter( Collision collision ) 
    {
        // Rotate the object so that the y-axis faces along the normal of the surface
        ContactPoint contact = collision.contacts[0];
        Quaternion   rot     = Quaternion.FromToRotation(Vector3.up, contact.normal);
        Vector3      pos     = contact.point;
        Instantiate(explosionPrefab, pos, rot);
        // Destroy the projectile
        
    }
}

I can’t figure it out how to edit the script, so I can specify in the inspector at which object-collision the script should spawn my prefab. Thanks for help in advance :slight_smile:

the simplest solution is to add in the inspector a tag to the gameobjects you want them to collide and instantiate the explosion and inside the collision enter check the tag

void OnCollisionEnter( Collision collision ) 
     {
          if(collision.gameObject.tag != "TheCollisionTag")
               return;

         // Rotate the object so that the y-axis faces along the normal of the surface
         ContactPoint contact = collision.contacts[0];
         Quaternion   rot     = Quaternion.FromToRotation(Vector3.up, contact.normal);
         Vector3      pos     = contact.point;
         Instantiate(explosionPrefab, pos, rot);
         // Destroy the projectile
         
     }