通过SceneManager来管理场景
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//SceneManager的命名空间
using UnityEngine.SceneManagement;

public class Manager : MonoBehaviour {

	void Start () {
		StartCoroutine (LoadScene ());
	}

	IEnumerator LoadScene(){
		SceneManager.LoadScene ("12", LoadSceneMode.Additive);
		yield return new WaitForSeconds(5f);
		SceneManager.UnloadSceneAsync ("12");
		yield return new WaitForSeconds (1f);
		//加载下一个场景
		SceneManager.LoadScene("20",LoadSceneMode.Additive);
	}
}

可以认为这个就是管理场景的一个脚本,而这个场景就是那个将会一直存在的场景

通过这个场景的管理类,额外的添加其他的场景,也可以在不需要时卸载,再添加其他场景

从而实现了一种不用DontDestroyOnLoaded的更好办法,场景特么也成为一种组件的形式了


首页 我的博客
粤ICP备17103704号