관리 메뉴

caLAB

sceneLoader 본문

Unity/유니티 개발

sceneLoader

도이(doi) 2021. 3. 10. 22:47
728x90
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class sceneLoader : MonoBehaviour
{
    public float sceneTime = 15.0f;
    public Image panel;

    float F_time = 1f;
    Scene sceneLoaded;
    float time = 0f;

    private void Start()
    {
        sceneLoaded = SceneManager.GetActiveScene();
        sceneLoad();
    }

    public void sceneLoad()
    {
        StartCoroutine(WaitForSceneLoad());
    }
    private IEnumerator WaitForSceneLoad()
    {
        yield return new WaitForSeconds(sceneTime);
        StartCoroutine(FadeFlow());
    }

    IEnumerator FadeFlow()
    {
        panel.gameObject.SetActive(true);
        time = 0f;
        Color alpha = panel.color;
        while (alpha.a < 1f)
        {
            time += Time.deltaTime / F_time;
            alpha.a = Mathf.Lerp(0, 1, time);
            panel.color = alpha;
            yield return null;
        }

        time = 0f;
        SceneManager.LoadScene(sceneLoaded.buildIndex + 1);
    }
}
728x90
반응형
Comments