I want some particles to get activated when a bullet hits the enemy spaceship in my top down 2D game.
So i wrote a script where i use collision tags to check if its the bullet that has hit the enemy or not.
using UnityEngine;
public class EnemyAnimationScript : MonoBehaviour
{
public ParticleSystem sparks1;
bool isPlaying = true;
private void OnCollisionEnter2D(Collision2D collision)
{
if(collision.gameObject.tag == "Bullet" && isPlaying == false)
{
sparks1.Play();
isPlaying= false;
}
}
}
But this doesn’t seem to work.
- I created a prefab of the particle effect and added it as a child of my enemy. This makes the particle effect start as soon as the game starts
- I referenced the prefab using my script without keeping it in Hierarchy. This doesn’t even play the animation cause the game doesn’t know where to play the particles
Please HELP!!
Btw those explosion effects work because they are game objects. But those sparks on the red spaceship don’t work