All i want to do is every time my character jumps on an enemy it is destroyed and the particle effect plays.
ive made a particle effect but i just want it played when the enemy is destroyed.
this is the code i have for my particle. it is a child of a cube object.
how do i do that?
OK then set it to “Play On Awake” and Instantiate it with OnCollisionEnter or OnTriggerEnter depending on how your Colliders are Setup. The script that Instantiates the GameObject with the Particle System on it should be attached to the GameObject (your Player Object or whatever collides with the Enemy) that collides with the Enemy. It could look like this:
public class FxOnCollision : MonoBehaviour{
public GameObject FX;
void OnCollisionEnter(Collision collision){
if(collision.gameObject.tag == "Enemy")
GameObject o=Instantiate(FX,collision.transform.Position,Quaternion.identity);
Destroy(o,3f);
}
}
you Need to attach your Particle System Prefab to FX in Inspector and your Enemies should have a Tag called “Enemy” then it should work.