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

public class ParticleSystemDestroyOnCollision : MonoBehaviour
{
    public string dontDestroyTag = "dontDestroy";
    public GameObject prefabToSpawn;

    ParticleSystem ps;
    List<ParticleCollisionEvent> collisionEvents;
    void Start()
    {
        ps = GetComponent<ParticleSystem>();
        collisionEvents = new List<ParticleCollisionEvent>();
    }

    private void OnParticleCollision(GameObject other)
    {
        if (!other.CompareTag(dontDestroyTag))
        {
            // if you want to generate something from the collision you can
            if (prefabToSpawn)
            {
                var obj = Instantiate(prefabToSpawn, other.transform.position, Random.rotation);
                // you can also destroy the object on a delay
                Destroy(obj, 3);
            }

            // destroy the game object
            // to also destroy the particle, adjust the kill speed in the particle system
            Destroy(other);
        }
            
    }
}
