SetMiniGame.cs 1.08 KB
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class SetMiniGame : MonoBehaviour
{
    static public SetMiniGame Instance;
    public GameObject UIButton;
    public Image backPanel;

    private Color m_color;

    private float fadeTime = 1f;
    float start;
    float end;
    float time = 0f;

    private void Awake()
    {
        Instance = this;
    }


    public void SetButton(bool open)
    {
        UIButton.SetActive(open);
    }

    public void StartMiniGameScene()
    {
        StartCoroutine(ImageFadeOut());
    }


    protected IEnumerator ImageFadeOut()
    {
        m_color.a = 0f;
        m_color = backPanel.color;
        start = 0f; end = 1f; time = 0f;

        backPanel.gameObject.SetActive(true);
        while (m_color.a < 1f)
        {
            time += Time.deltaTime / fadeTime;
            m_color.a = Mathf.Lerp(start, end, time);
            backPanel.color = m_color;
            yield return null;
        }
        SceneManager.LoadScene("MiniGameScene");
    }
}