using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class AsyncTest : MonoBehaviour
{
AsyncOperation operation;
// Start is called before the first frame update
void Start()
{
StartCoroutine(loadScene());
}
//协程方法用来异步加载场景
IEnumerator loadScene(){
operation = SceneManager.LoadSceneAsync(1);
//加载完场景不要自动跳转
//operation.allowSceneActivation 默认为true,意味自动跳转
operation.allowSceneActivation = false;
yield return operation;
}
float timer = 0;
// Update is called once per frame
void Update()
{
//输出加载进度 0-0.9 最大为0.9
Debug.Log(operation.progress);
timer += Time.deltaTime;
//如果到达5秒,再跳转
if (timer > 5){
operation.allowSceneActivation = true;
}
}
}
Unity 异步加载场景
最新推荐文章于 2025-05-25 08:49:35 发布