方法:加载场景
引用包:using UnityEditor.SceneManagement;
通过场景名或场景索引加载场景:EditorSceneManager.LoadScene(索引值/场景名称);
异步加载场景:EditorSceneManager.LoadSceneAsync(索引值/场景名称);
步骤:
unity工具对场景切换的预览时有小bug:切换场景的物体没有光照效果,不过发布后这个问题就不存在了。
1.添加场景
2.脚本切换场景(只能切换添加的场景)
public class LevelTest : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.A))
{
//加载场景
//EditorSceneManager.LoadScene(0);
//异步加载
EditorSceneManager.LoadSceneAsync("AudioTest");
}
}
}