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

public class MenuC : MonoBehaviour
{
    [SerializeField] private float speed = 1;
    private CanvasGroup group;
    private float targetAlpha;

    private bool starting => this.speed < 0;

    // Start is called before the first frame update
    void Awake()
    {
        this.group = this.GetComponent<CanvasGroup>();
        this.targetAlpha = 1f;
    }

    // Update is called once per frame
    void Update()
    {
        this.group.alpha = Mathf.Lerp(0, 1, Time.deltaTime * this.speed + this.group.alpha);

        if (!this.starting)
        {
            if (Input.GetKeyDown(KeyCode.Joystick1Button0))
            {
                this.StartPlay();
            }
            else if (Input.GetKeyDown(KeyCode.Joystick1Button1))
            {
                this.Quit();
            }
        }

        if (this.starting && this.group.alpha == 0)
        {
            SceneManager.LoadScene("SampleScene");
        }
    }

    public void StartPlay()
    {
        if (this.starting)
        {
            return;
        }

        this.speed = -this.speed;
    }

    public void Quit()
    {
        Application.Quit();
    }
}
