using UnityEngine;

public class Tnt : MonoBehaviour
{
    public Light explodeLight;
    public ParticleSystem explodeParticle;
    public Explosion explosion;

    public float fuseTime;
    public float explosionLengthTime;
    float timer = 0;
    private bool exploded = false;

    void Update()
    {
        timer += Time.deltaTime;

        if (!exploded && timer > fuseTime)
        {
            exploded = true;
            explosion.gameObject.SetActive(true);
            explosion.transform.parent = null;
            explodeLight.gameObject.SetActive(true);
            explodeLight.transform.parent = null;
            explodeParticle.gameObject.SetActive(true);
            explodeParticle.transform.parent = null;
            explodeParticle.transform.localScale = new Vector3(0.05f, 0.05f, 0.05f);
            explodeParticle.Play();

            Destroy(explodeLight.gameObject, explosionLengthTime);
            Destroy(explodeParticle.gameObject, explosionLengthTime);
            Destroy(explosion.gameObject, 0.1f);

            Destroy(gameObject);
        }
    }
}
