Isoulated/Assets/Scripts/Level/LevelLoader.cs
Gerard Gascón 001bb14f16 init
2025-04-24 17:19:36 +02:00

27 lines
679 B
C#

using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class LevelLoader : MonoBehaviour{
public GameObject loadingScreen;
public Slider slider;
public void LoadLevel(int sceneIndex){
StartCoroutine(LoadAsychronously(sceneIndex));
}
IEnumerator LoadAsychronously (int sceneIndex){
AsyncOperation operation = SceneManager.LoadSceneAsync(sceneIndex);
loadingScreen.SetActive(true);
while (!operation.isDone){
float progress = Mathf.Clamp01(operation.progress / .9f);
slider.value = progress;
yield return null;
}
}
}