using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;

public class LesMegaSpotlightsScript : MonoBehaviour
{
    public List<GameObject> megaSpotlights;
    bool oneSpotlightIsOn;
    float timer;

    void Start()
    {
        timer = 0;
        oneSpotlightIsOn = false;
        megaSpotlights = new List<GameObject>();
        foreach (Transform child in transform)
        {
            megaSpotlights.Add(child.gameObject);
            child.gameObject.SetActive(false);
        } 

    }


    void Update()
    {
        if (PlayerScript.isPlaying)
        {
            timer += Time.deltaTime;
            if (oneSpotlightIsOn == false && timer > 3f)
            {
                Debug.Log("Spotlight enabled");
                megaSpotlights[Random.Range(0,megaSpotlights.Count)].SetActive(true);
                oneSpotlightIsOn = true;
                timer = 0;
            }
        }
    }


    void SpotlightDisabled()
    {
        Debug.Log("Spotlight disabled");
        timer = 0;
        oneSpotlightIsOn = false;
    }

    public void ActivateAll()
    {
        foreach (GameObject spot in megaSpotlights)
        {
            spot.SetActive(true);
            spot.GetComponent<Light>().intensity = 25f;
            spot.GetComponent<Light>().DOIntensity(0,Random.Range(0.05f,0.2f)).SetLoops(-1,LoopType.Yoyo);
        }
    }

  


}
