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

public class MainMenu : MonoBehaviour
{
    public bool StartSolid = false;
    private float Alpha = 0;
    public float FadeSpeed = 1;
    private bool FadeIn = false;
    public string NextLevel = "GAME";
    private bool IsBusy = false;

    // Start is called before the first frame update
    void Start()
    {
        Alpha = StartSolid ? 1 : 0;
    }

    // Update is called once per frame
    void Update()
    {
        if (IsBusy)
            return;
        if(FadeIn)
        {
            if (Alpha < 1)
                Alpha += Time.smoothDeltaTime * FadeSpeed;
            else
            {
                Alpha = 1;
                UnityEngine.SceneManagement.SceneManager.LoadScene(NextLevel);
                IsBusy = true;
            }
        }
        else
        {
            if (Alpha > 0)
                Alpha -= Time.smoothDeltaTime * FadeSpeed;
            else
                Alpha = 0;
        }
    }

    public void GoToNextScene()
    {
        FadeIn = true;
    }

    private void OnGUI()
    {
        if (Alpha > 0)
        {
            GUI.color = new Color(0, 0, 0, Alpha);
            GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), Texture2D.whiteTexture, ScaleMode.StretchToFill);
        }
    }
}
