using UnityEngine;
using System.Collections;

public class ObjectOcclusionOcludee : MonoBehaviour
{
    private bool m_isVisible;
    public bool inFixedLight;

    public float animTime = 0.35f;

    private float m_animTimer;

    private void Awake()
    {
        ObjectOcclusion.Instance.AddOcludee(this);
        //SetVisible(false);
    }

    private void Update()
    {
        if(m_animTimer < animTime)
        {
            //transform.localScale = Vector3.Lerp(Vector3.zero, Vector3.one, m_isVisible ? (m_animTimer / animTime) : (1f - m_animTimer / animTime));
            m_animTimer += Time.deltaTime;
        }
        else
        {
            if(!m_isVisible)
            {
                gameObject.SetActive(false);
            }
        }
    }

    private void OnDestroy()
    {
        ObjectOcclusion.Instance.RemoveOccludee(this);
    }
    
    public void SetVisible(bool visible)
    {
        m_isVisible = visible;

        if (visible) gameObject.SetActive(true);

        m_animTimer = 0f;
    }
}
