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

namespace ToadieTechnika.GGJ2018Game
{
    public class GGJSplash : MonoBehaviour
    {
        [SerializeField]
        CanvasGroup m_CanvasGroup;

        void Start()
        {
            StartCoroutine("SplashSequence");
        }

        IEnumerator SplashSequence()
        {
            m_CanvasGroup.alpha = 0;
            yield return new WaitForSeconds(0.5f);

            while (m_CanvasGroup.alpha < 1)
            {
                yield return new WaitForEndOfFrame();
                m_CanvasGroup.alpha = Mathf.MoveTowards(m_CanvasGroup.alpha, 1, Time.deltaTime);
            }

            yield return new WaitForSeconds(2.5f);
            AsyncOperation _AsyncOperation = SceneManager.LoadSceneAsync("GameScene");

            while (!_AsyncOperation.isDone)
                yield return _AsyncOperation;

            yield return null;
        }
    }
}