Unity加載場景、計時器、加載時不銷毀某物體


異步加載場景,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 }

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM