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

public class LightHeartbeat : MonoBehaviour
{
    public int _minSpotAngle = 80;
    public float _minIntensity = 20.0f;

    public int _maxSpotAngle = 160;
    public float _maxIntensity = 42.0f;

    private int _maxSteps = 100;
    private int _step;
    private bool _glowing;

    void Start()
    {
        _glowing = true;
        _step = 0;

        Light light = GetComponent<Light>();
        light.intensity = _minIntensity;
        light.spotAngle = _minSpotAngle;
    }

    void Update()
    {
        
    }
    
    void FixedUpdate()
    {
        _step++;

        float intensityIncrement = ((_maxIntensity - _minIntensity) / _maxSteps) * _step;
        float spotAngleIncrement = ((_maxSpotAngle - _minSpotAngle) / (float) _maxSteps) * _step;

        float intensity = 0.0f;
        int spotAngle = 0;
        if (_glowing)
        {
            intensity = _minIntensity + intensityIncrement;
            spotAngle = _minSpotAngle + (int) spotAngleIncrement;
        } 
        else
        {
            intensity = _maxIntensity - intensityIncrement;
            spotAngle = _maxSpotAngle - (int) spotAngleIncrement;
        }

        if (_step >= _maxSteps)
        {
            _step = 0;
            _glowing = !_glowing;
        }
        
        Light light = GetComponent<Light>();
        light.intensity = intensity;
        light.spotAngle = spotAngle;
    }
}
