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

public class LampSwitch : MonoBehaviour
{
    public GameObject[] lightsToSwitch;
	InputToPress inputToPress;
	static bool showed = false;

    public AudioSource lampioneAudioSource;

	// Start is called before the first frame update
	void Start()
    {
        inputToPress = FindObjectOfType<InputToPress>();
        lampioneAudioSource = GetComponent<AudioSource>();
    }

    // Update is called once per frame
    void Update()
    {

    }

    public void activate() {
        lampioneAudioSource.PlayOneShot(lampioneAudioSource.clip);
        //Debug.Log(lampioneAudioSource.clip);
        foreach (GameObject obj in lightsToSwitch) {
			for (int i = 0; i < obj.transform.childCount; i++) {
				GameObject child = obj.transform.GetChild(i).gameObject;
				child.SetActive(!child.activeSelf);
			}
        }
    }

	public void OnTriggerEnter(Collider other) {
		inputToPress.Activate(KeyCode.Return);
		if(!showed) {
			inputToPress.Invoke("Deactivate", 1);
			showed = true;
		}
	}

	public void OnTriggerExit(Collider other) {
		inputToPress.Deactivate();
	}
}
