using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DeleteWhenParticleAndSoundComplete : MonoBehaviour {

    private ParticleSystem ps;
    private AudioSource audiosrc;


    public void Start()
    {
        ps = GetComponent<ParticleSystem>();
        audiosrc = GetComponent<AudioSource>();
    }

    public void Update()
    {
        bool psExistsAndIsDone = false;
        if (ps)
        {
            if (!ps.IsAlive())
            {
                psExistsAndIsDone = true;
            }
        }

        bool audioExistsAndIsDone = false;
        if (audiosrc)
        {
            if (!audiosrc.isPlaying)
            {
                audioExistsAndIsDone = true;
            }
        }

        if (psExistsAndIsDone && audioExistsAndIsDone)
            Destroy(gameObject);
    }
}
