I want to make a game where you have to destroy game objects, on a destroy you see a particle effect. it is starting on destroying but it won’t stop. This is my code:
using UnityEngine;
using System.Collections;
public class RedEnemy : MonoBehaviour
{
[SerializeField] private AudioSource _as;
[SerializeField] private AudioClip _explosionSound;
public GameObject FireworksAll;
void Start()
{
}
void Update()
{
}
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.tag == "player")
{
Destroy(gameObject);
Explode();
_as.PlayOneShot(_explosionSound);
}
}
void Explode()
{
GameObject firework = Instantiate(FireworksAll, transform.position, Quaternion.identity);
firework.GetComponent<ParticleSystem>().Play();
}
}