using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; public class LevelChanger : MonoBehaviour { Animator animator; private int? levelToLoadIndex; private string levelToLoadName; private void Awake() { animator = GetComponent(); } // Update is called once per frame void Update() { } public void FadeToScene(int sceneIndex) { levelToLoadIndex = sceneIndex; animator.SetTrigger("FadeOut"); } public void FadeToScene(string sceneName) { levelToLoadName = sceneName; animator.SetTrigger("FadeOut"); } public void OnFadeComplete() { if (levelToLoadIndex.HasValue) { SceneManager.LoadScene(levelToLoadIndex.Value); levelToLoadIndex = null; } else if(levelToLoadName != null) { SceneManager.LoadScene(levelToLoadName); levelToLoadName = null; } } }