using UnityEngine;

public class Practical2 : MonoBehaviour
{
    public Light candleLight;        // Reference to the Light component
    public GameObject smokeEffect;   // Reference to the smoke effect

    private bool isLit = false;

    void Start()
    {
        // Find the Light component on the GameObject with the tag "Light"
        GameObject lightObj = GameObject.FindGameObjectWithTag("Light");
        
        if (lightObj != null)
        {
            candleLight = lightObj.GetComponent<Light>();
        }

        // Initially keep the light and smoke off
        if (candleLight != null)
            candleLight.enabled = false;

        if (smokeEffect != null)
            smokeEffect.SetActive(false);
    }

    void OnMouseDown()
    {
        Debug.Log("Candle clicked!");

        // Only toggle the light if it isn't already lit
        if (!isLit)
        {
            // Turn on the light
            if (candleLight != null)
            {
                candleLight.enabled = true;
                Debug.Log("Light turned ON");
            }
            else
            {
                Debug.LogError("candleLight not assigned or found!");
            }

            // Turn on the smoke effect
            if (smokeEffect != null)
            {
                smokeEffect.SetActive(true);
                Debug.Log("Smoke effect turned ON");
            }
            else
            {
                Debug.LogError("smokeEffect not assigned!");
            }

            isLit = true;
        }
    }
}
