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

[RequireComponent(typeof(Renderer))]
public class AnimateEmission : MonoBehaviour
{
    public float rate = 3f;
    public Color baseColor;

    private Renderer m_renderer;

    private readonly int m_emissionPropID = Shader.PropertyToID("_EmissionColor");

    private void Awake()
    {
        m_renderer = GetComponent<Renderer>();
    }

    private void Update()
    {
        float floor = 0.5f;
        float ceiling = 1f;
        float emission = floor + Mathf.PingPong(Time.time * rate, ceiling - floor);

        Color finalColor = baseColor * Mathf.LinearToGammaSpace(emission);

        m_renderer.material.SetColor(m_emissionPropID, finalColor);
    }
}
