using System.Collections;
using UnityEngine;

public class PageController : MonoBehaviour
{
    private CanvasGroup canvasManager;

    private void Awake()
    {
        canvasManager = GetComponent<CanvasGroup>();
    }

    private IEnumerator Lerp(bool display, float time)
    {
        float t = 0;
        while (t <= time)
        {
            if (display)
            {
                canvasManager.alpha = Mathf.Lerp(0, 1, t / time);
            }
            else
            {
                canvasManager.alpha = Mathf.Lerp(1, 0, t / time);
            }

            t += Time.deltaTime;
            yield return null;
        }

        StopCoroutine(Lerp(display, time));
    }

    public void Display()
    {
        StartCoroutine(Lerp(true, 5));
    }

    public void Hide()
    {
        StartCoroutine(Lerp(false, 5));
    }
}