using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class Loading : MonoBehaviour
{
static string nextLevel;
AsyncOperation async;
public Text Text;
public Slider slider;
public float tempProgress;
void Start()
{
tempProgress = 0;
if (SceneManager.GetActiveScene().name == "Loading")
{
async = SceneManager.LoadSceneAsync(nextLevel);
async.allowSceneActivation = (false);
}
}
public void LoveManager(string nextLevelName)
{
nextLevel = nextLevelName;
SceneManager.LoadScene("Loading");
}
void Update()
{
if (Text && slider)
{
tempProgress = Mathf.Lerp(tempProgress, async.progress, Time.deltaTime);
Text.text = ((int)(tempProgress / 9 * 10 * 100)).ToString() + "%";
slider.value = tempProgress / 9 * 10;
if (tempProgress / 9 * 10 > 0.995)
{
tempProgress = 1;
Text.text = 100.ToString() + "%";
slider.value = 1;
async.allowSceneActivation = (true);
}
}
}
}
异步加载
最新推荐文章于 2024-07-04 23:22:27 发布