Creating an impact particle when enemy hits enemy

When an enemy fires a projectile and it hits another enemy I would like the projectile to impact the enemy, create an impact particle, and be destroyed. I have created a script which successfully does this in testing, but when an enemy actually fires the projectile it is destroyed right away. This is what I have:

{
    
    public GameObject impactParticle;
    public Vector3 impactNormal;


    void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.tag == "Enemy")
        {
            
            impactParticle = Instantiate(impactParticle, transform.position,

            Quaternion.FromToRotation(Vector3.up, impactNormal)) as GameObject;

            Destroy(gameObject);

        }
    }
}

I thought the use of ‘other’ would mean the enemy firing the projectile would be ignored, but this apparently isn’t the case?

try using Destroy(gameObject, 3);

Alternatively, I would not use the Destroy method. I would create the prefab to destroy its self on completion. I think that stuff is still in the particle system.

The problem i’m having is the impact particle is triggering right away, so delaying the destroy wont help.

Other refers to the collider entering the trigger.

ok, your code creates an instance of an emitter object, it then destroys the current object.

This part is true, but what you are saying is that it also destroys the emitter. This is not written in your code.

Now, if you parent the ParticleSystem to your object, then destroy the object, it would remove both.

ParticleSystem’s do not auto-destroy, you need some code to do this:

I guess the projectile is colliding with the enemy who is firing it which is why it triggers instantly. I have found a quick workaround, if I disable the sphere collider of the projectile and enable it via script after 0.18 seconds the projectile explode trigger isn’t set off prematurely. I will have to playtest and see if this is going to be a good solution in the long run.