Chess-II-Counterattack/Assets/Scripts/SceneLoader.cs
Gerard Gascón 78b901484a init
2025-04-24 17:43:50 +02:00

45 lines
1.1 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class SceneLoader : MonoBehaviour{
[System.Serializable] public enum DifficultySelected {Easy, Hard}
public DifficultySelected difficultySelected;
Animator anim;
public static SceneLoader instance;
void Awake(){
if(instance == null){
instance = this;
}else{
Destroy(gameObject);
return;
}
DontDestroyOnLoad(gameObject);
anim = GetComponent<Animator>();
}
public void LoadScene(int scene, DifficultySelected difficulty){
anim.SetTrigger("FadeOut");
StartCoroutine(SceneChange(scene, difficulty));
}
IEnumerator SceneChange(int scene, DifficultySelected difficulty){
yield return new WaitForSeconds(1);
difficultySelected = difficulty;
AsyncOperation operation = SceneManager.LoadSceneAsync(scene);
while (!operation.isDone)
yield return null;
if (operation.isDone){
anim.SetTrigger("FadeIn");
}
}
}