Can't find a way to add particle effects to a collision

And before you tell me to use google or to search in the web, let me tell you I’ve been researching about this for about 3 hours and I simply can’t find an answer. All I find is old topics that work with the old particle system and we all know most of that code is obsolete now.

I’m kinda new with Unity so if you could be quite specific, even better. My problem is this:

I have 3 main scripts for this, one for the enemy health, one for the player weapon and one for the action of firing itself. In enemy health I specify enemy’s status and I use OnCollisionEnter to deal damage when my bullet hits, with a reference to my player weapon script for damage and other data. The firing scripts basically instanciates the bullet with a rigidbody component and adds the movement.

Now I can’t find a way to simply play an animation in the spot where the bullet hits when it collisions with the enemy. That’s all I want and I can’t get to understand how to work with ParticleSystem, GetComponent and “Play()” to make it work as I read here and there.

This is my code to instanciate the bullet itself:

    void Shoot()
    {
        shot = Instantiate(shotEmitter) as GameObject;
        shot.transform.position = transform.position + Camera.main.transform.forward * 2;
        Rigidbody rb = shot.GetComponent<Rigidbody>();
        rb.velocity = Camera.main.transform.forward * 40;
        Destroy(shot, 2f);
    }

And to cause the damage and destroy the bullet on contact:

    void OnCollisionEnter(Collision _col)
    {
        if (_col.collider.gameObject.tag == "Bullet")
        {
            GameObject theDamage = GameObject.Find("Gun");
            PlayerWeapon damageFromWeapon = theDamage.GetComponent<PlayerWeapon>();
            currentEnemyHealth -= damageFromWeapon.weaponDamage;
            WeaponFiring theShot = theDamage.GetComponent<WeaponFiring>();
            Destroy(theShot.shot);
        }
    }

Is there any way to add a particle system (I acutally created one in an empty object and all) to the point where it hits? If you need any other info let me know.

You can create a prefab as an empty gameObject with a particle system attached to it, with necessary settings as per your wish. When your bullet hits the collider, which I think you have mentioned in your second part of code, just before destroying the bullet, you can instantiate the particle system prefab at the position of the co-ordinate, then destroy the bullet and afterwards destroy the prefab so as not to hog up memory. I am sorry as I currently don’t have any code for it, but it should be easy for you to figure it out. I think most of this functionality will happen just before Destory(theShot.shot)

public GameObject explosion; // I’m Guessing it’s an explosion you want to show
void OnCollisionEnter(Collision _col)
{
if (_col.collider.gameObject.tag == “Bullet”)
{
GameObject theDamage = GameObject.Find(“Gun”);
PlayerWeapon damageFromWeapon = theDamage.GetComponent();
currentEnemyHealth -= damageFromWeapon.weaponDamage;
WeaponFiring theShot = theDamage.GetComponent();
Instantiate(explosion, transform.position, Quaternion.Identity);
Destroy(theShot.shot);
}
}

Then on the explosion gameobject you can add your animation component or your particle system, then after the explosion gameobject is instantiated you will need to destroy it.
So add a script to the explosion gameobject like so :

 int destroyTime = 2f;  
> Start(){
> Destroy(gameObject, destroyTime);
> }

PS: This is a place meant for people to ask questions about this stuff. If anyone gives you a hard time
telling you to use google don’t pay them no mind. Many if not most people on here are very helpful :).
Hope this helps!