I want to create a loading scene based on time and LoadSceneAsync and I write below code but didn’t work. my mean is time * LoadSceneAsync = progress
How I can do that?
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using UnityEngine.SceneManagement;
public class LoadingScreenBarSystem : MonoBehaviour {
public float timer = 12f;
private Text timersecounds;
public GameObject bar;
public Text loadingText;
public bool backGroundImageAndLoop;
public float LoopTime;
public int SceneNumber;
public GameObject[] backgroundImages;
[Range(0, 1f)] public float vignetteEfectVolue; // Must be a value between 0 and 1
AsyncOperation async;
Image vignetteEfect;
private void Start()
{
this.gameObject.SetActive(true);
StartCoroutine(Loading(SceneNumber));
vignetteEfect = transform.Find("VignetteEfect").GetComponent<Image>();
vignetteEfect.color = new Color(vignetteEfect.color.r, vignetteEfect.color.g, vignetteEfect.color.b, vignetteEfectVolue);
if (backGroundImageAndLoop)
StartCoroutine(transitionImage());
}
// The pictures change according to the time of
IEnumerator transitionImage()
{
for (int i = 0; i < backgroundImages.Length; i++)
{
yield return new WaitForSeconds(LoopTime);
for (int j = 0; j < backgroundImages.Length; j++)
backgroundImages[j].SetActive(false);
backgroundImages*.SetActive(true);*
}
}
// Activate the scene
IEnumerator Loading(int sceneNo)
{
async = SceneManager.LoadSceneAsync(sceneNo);
async.allowSceneActivation = false;
// Continue until the installation is completed
while (async.isDone == false)
{
bar.transform.localScale = new Vector3(async.progress, 0.9f, 1);
if (loadingText != null)
loadingText.text = “%” + (108.57 * bar.transform.localScale.x).ToString(“####”);
if (async.progress == 0.9f)
{
bar.transform.localScale = new Vector3(1, 0.9f, 1);
//asli async.allowSceneActivation = true;
}
yield return null;
}
timer -= Time.deltaTime;
timersecounds.text = timer.ToString(“f0”);
if (timer <= 0 && async.progress == 0.9f)
{
async.allowSceneActivation = true;
}
}
}