Hi!
I’ve got a BulletPrefab with a Particle System attached to it (as child). Hitting the FireButton instatiates clones of my bullet. Everything’s working fine so far. I want the Particle System to emit whenever a bullet hits a collider (obstacles, other players and so on) at the exact position where the bullet hits said colliders. This only works for the first time. I start the game, shoot at an enemy1 and the particle effect appears right there where it collides with enemy1. Shooting enemy2 results in the particle effect appearing at the position from enemy1. That is obviously not what I want. I need the particle effect to appear on different locations, exactly there where the Bullet hits an collider.
Here’s the code I wrote. It’s attached to the BulletPrefab.
void OnTriggerEnter2D(Collider2D otherCollider){
GameObject.FindGameObjectWithTag ("Splash").GetComponent<ParticleSystem> ().transform.parent = null;
GameObject.FindGameObjectWithTag ("Splash").GetComponent<ParticleSystem> ().Play ();
}
The bullets are destroyed as soon as they hit a collider and to prevent the destruction of the particle System as well I need to detach it from its parent.
So here’s my question: What can I do to move the Particle Systems location to wherever the new instatiated bullet hits a collider?
Thanks in advance! And if you need more information, just let me know.