So I am really new to C# scripting and just wanted to create a loading screen for my game. I copied off of a youtuber (Solo Game Dev) and smth pops up about the IEnumerator. any help is appreciated.
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class LoadingScript : MonoBehaviour
{
public GameObject LoadingScreen;
public Image LoadingBarFill;
public void LoadScene(int sceneId)
{
StartCoroutine(LoadSceneAsync(sceneId));
}
IEnumerator LoadSceneAsync(int sceneId)
{
AsyncOperation operation = SceneManager.LoadSceneAsync(sceneId);
LoadingScreen.SetActive(true);
while (!operation.isDone)
{
float progressValue = Mathf.Clamp01(operation.progress / 0.9f);
LoadingBarFill.fillAmount = progressValue;
yield return null;
}
}
}