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

public class BoundaryLightManager : MonoBehaviour
{
    public AudioClip bounceSFX;
    public Light currentLight;
    public float startIntensity;
    public float lightLifeTime;
    public bool doSFX = false;

    private AudioSource _currentAudioSource;
    private TimerHelper _lightTimer;

    // Start is called before the first frame update
    void Start()
    {
        currentLight.intensity = startIntensity;
        _lightTimer = new TimerHelper(lightLifeTime, false);
        _currentAudioSource = gameObject.GetComponent<AudioSource>();
    }

    // Update is called once per frame
    void Update()
    {
        if (!GameEngine.isPaused)
        {
            if (doSFX)
            {
                if (_currentAudioSource != null)
                {
                    _currentAudioSource.PlayOneShot(bounceSFX);
                    doSFX = false;
                }
            }
            currentLight.intensity = startIntensity - Mathf.Lerp(0, startIntensity, _lightTimer.Position);
            if (_lightTimer.HasTicked(Time.deltaTime))
            {
                Destroy(gameObject);
            }
        }
    }
}
