#How to delete objects when linked objects delete

1 messages · Page 1 of 1 (latest)

light sundial
#

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);
    }
}

}

shut vine
#

Can you explain what you mean by "linked GameObject"?

#

To destroy the particle system you can do a few different things:

cunning night
#

The Stop Action is perfect for this use case

light sundial
#

I'll try these out.