12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- public class BackVillage : MonoBehaviour
- {
- // Start is called before the first frame update
- private AsyncOperation async;//异步加载的对象
- private int Progress = 0;//定义进度条数
- void Awake()
- {
- }
- void Start()
- {
- StartCoroutine(LoadAsync());
- }
- // Update is called once per frame
- void Update()
- {
- if (Input.GetKeyDown(KeyCode.B))
- { StartCoroutine(LoadAsync()); }
- if (async == null)
- {
- return;
- }
- int toProcess;
- if (async.progress < 0.9f)
- {
- toProcess = (int)(async.progress * 100);
- }
- else
- {
- toProcess = 100;
- }
- if (Progress < toProcess)
- {
- Progress++;
- Debug.Log(Progress + "进度");
- }
- if (Progress == 100)
- {
-
- Debug.Log("跳转");
- }
- }
- public void tiaozhuan()
- {
- if (Progress>99)
- {
-
- async.allowSceneActivation = true;
- }
- }
- IEnumerator LoadAsync()
- {
- async = SceneManager.LoadSceneAsync(1);//加上场景名
- async.allowSceneActivation = false;//不激活场景转换
- yield return async;
- }
- }
|