異步加載場景,SceneManager.LoadSceneAsync(SceneName);需引用 using UnityEngine.SceneManagement;命名空間,
Application.LoadLevel這個方法不再適用;
可以用協同程序做一個簡單的計時器,詳見代碼;
DontDestroyOnLoad (this.gameObject);方法可以在加載場景時不銷毀指定物體;
1 using System.Collections; 2 using System.Collections.Generic; 3 using UnityEngine; 4 using UnityEngine.SceneManagement; 5 6 public class Base : MonoBehaviour { 7 8 public virtual void ScenesLoad(string SceneName,int AfterSomeMinutesToLoad) 9 { 10 StartCoroutine (Calculagraph(SceneName,AfterSomeMinutesToLoad)); 11 } 12 IEnumerator Calculagraph(string SceneName,int AfterSomeMinutesToLoad) 13 { 14 yield return new WaitForSeconds (AfterSomeMinutesToLoad*60); 15 DontDestroyOnLoad (this.gameObject); 16 SceneManager.LoadSceneAsync(SceneName); 17 } 18 }
