using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class LoadingBarScript : MonoBehaviour
{
public Text loadingText;
public Slider sliderBar;
private AsyncOperation async;
private int curProgressVaule = 0;
void Start()
{
StartCoroutine(LoadScene());
}
IEnumerator LoadScene()
{
async = SceneManager.LoadSceneAsync("SampleScene");
async.allowSceneActivation = false;
yield return async;
}
void Update()
{
if (async == null)
{
return;
}
int progressVaule = 0;
if (async.progress < 0.9f)
{
progressVaule = (int)async.progress * 100;
}
else
{
progressVaule = 100;
}
if (curProgressVaule < progressVaule)
{
curProgressVaule++;
}
sliderBar.value = curProgressVaule / 100.0f;
loadingText.text = curProgressVaule + "%";
if (curProgressVaule == 100)
{
async.allowSceneActivation = true;
}
}
}