using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; public class SceneLoader : MonoBehaviour{ Animator anim; [SerializeField, Range(0f, 3f)] float fadeDuration = 1f; public static SceneLoader instance; void Awake(){ instance = this; anim = GetComponent(); } /// Loads the scene. public void LoadScene(int scene){ StartCoroutine(LoadLevel(scene)); } IEnumerator LoadLevel(int scene){ if(anim != null) anim.SetTrigger("Fade"); yield return new WaitForSecondsRealtime(fadeDuration); Loader.Load(scene); } /// Loads the scene with a certain delay. public void LoadScene(int scene, float delay){ StartCoroutine(LoadLevel(scene, delay)); } IEnumerator LoadLevel(int scene, float delay){ yield return new WaitForSecondsRealtime(delay); if (anim != null) anim.SetTrigger("Fade"); yield return new WaitForSecondsRealtime(fadeDuration); //SceneManager.LoadSceneAsync(scene); Loader.Load(scene); } }