using UnityEngine;

public class ObjectHighlighter : MonoBehaviour
{
    private Color m_originalColor;
    public Color m_highlightedColor;

    private float m_timer;
    private bool m_fadeIn = true;
    
    void Start()
    {
        m_originalColor = GetComponent<Renderer>().material.color;
    }

    void Update()
    {
        if (m_fadeIn)
        {
            GetComponent<Renderer>().material.color = Color.Lerp(GetComponent<Renderer>().material.color, m_highlightedColor, 1.0f * Time.deltaTime);
            m_timer += 2.3f * Time.deltaTime;
        }
        else
        {
            GetComponent<Renderer>().material.color = Color.Lerp(GetComponent<Renderer>().material.color, m_originalColor, 1.0f * Time.deltaTime);
            m_timer += -2.3f * Time.deltaTime;
        }
        
        if (m_timer >= 2.0f)
        {
            m_fadeIn = false;
        }
        else if (m_timer <= 0.0f)
        {
            m_fadeIn = true;
        }
    }

    public void Reset()
    {
        GetComponent<Renderer>().material.color = m_originalColor;
    }
}