using System.Collections; using System.Collections.Generic; using UnityEngine; public class testscene : MonoBehaviour { // Start is called before the first frame update void Start() { LoadSceneWithProgress("TestScene1"); } // Update is called once per frame void Update() { } //异步加载场景 public void LoadSceneAsync(string sceneName) { StartCoroutine(LoadScene(sceneName)); } IEnumerator LoadScene(string sceneName) { AsyncOperation operation = Application.LoadLevelAsync(sceneName); while (!operation.isDone) { yield return null; } } //异步加载场景并添加进度条 public void LoadSceneWithProgress(string sceneName) { StartCoroutine(LoadSceneWithProgressCoroutine(sceneName)); } IEnumerator LoadSceneWithProgressCoroutine(string sceneName) { AsyncOperation operation = Application.LoadLevelAsync(sceneName); while (!operation.isDone) { float progress = Mathf.Clamp01(operation.progress / 0.9f); Debug.Log(progress); yield return null; } } }