I'm making a 2D game for the first time, and I have an enemy that explodes on death. The enemy spawns a particle system playing a death explosion, then deletes itself. My problem is that it doesn't delete the particle system with the enemy. I tried some code to delete the particle system with the enemy, but I couldn't get it to work. I was thinking that I could get the particle system to detect when a linked game object (the enemy) is deleted, then delete itself.
The code provided would be applied to the particle system. Linked to Destroy would be the object you check is deleted (AKA the enemy) I copied some code from a seperate project, so I am thinking that might be the issue.
using System.Runtime.CompilerServices;
using UnityEngine;
public class deleteUponDeath : MonoBehaviour
{
[SerializeField] private GameObject LinkedToDestroy;
void Start()
{
}
public void Damage(float damageAmount)
{
if (LinkedToDestroy == null)
{
Destroy(gameObject);
}
}
}