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

public class Glow : MonoBehaviour
{
    public enum GlowType
    {
        Scale, Alpha, Both
    }

    public GlowType glowType;
    public Graphic graphic;
    public float delay;
    public float multiplier = 1;

    public Vector2 maxScale, minScale;
    public float maxAlpha, minAlpha;

    Vector2 targetScale;
    float targetAlpha;
    IEnumerator Start()
    {
        while (true)
        {
            targetAlpha = maxAlpha;
            targetScale = maxScale;
            yield return new WaitForSeconds(delay);
            targetAlpha = minAlpha;
            targetScale = minScale;
            yield return new WaitForSeconds(delay);
        }
    }

    void Update()
    {
        if (glowType == GlowType.Scale || glowType == GlowType.Both)
        {
            transform.localScale = Vector2.Lerp(transform.localScale, targetScale, multiplier * Time.deltaTime);
        }
        if (glowType == GlowType.Alpha || glowType == GlowType.Both)
        {
            Color col = graphic.color;
            col.a = Mathf.Lerp(col.a, targetAlpha, multiplier * Time.deltaTime);
            graphic.color = col;
        }
    }
}
