using UnityEngine;

public class Smoke : MonoBehaviour
{
    public float smokeDuration = 1.5f; // Duration in seconds for the smoke effect

    public float sparkTimer = 0.1f; // Timer for spark effect

    public GameObject sparkEffectPrefab; // Prefab for the spark effect

    private float smokeTimer = 0.0f;

    private float sparkEffectTimer = 0.0f;

    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
    }

    // Update is called once per frame
    void Update()
    {
        smokeTimer += Time.deltaTime;

        if (smokeTimer >= smokeDuration)
        {
            Destroy(gameObject);
        } 
        else
        {
            sparkEffectTimer += Time.deltaTime;

            if (sparkEffectTimer >= sparkTimer)
            {
                sparkEffectTimer = 0.0f;
                Vector2 randomOffset = Random.insideUnitCircle * 0.1f;

                Instantiate(
                    sparkEffectPrefab, 
                    transform.position + new Vector3(randomOffset.x, randomOffset.y, 0),
                    Quaternion.identity
                );
            }
        }
    }
}
