- 场景跳转代码
using UnityEngine.SceneManagement; //引用命名空间
SceneManager.LoadScene("mainScene");//引号内为要跳转的场景名
SceneManager.LoadScene(0); //也可以是导入Bulid的场景序列
异步场景跳转
private Action prgCB = null;
private void Update()
{
prgCB?.Invoke();
}
public void LoadSceneAsync(string sceneName)
{
AsyncOperation asyncOperation = SceneManager.LoadSceneAsync(sceneName);
prgCB = () =>
{
float val = asyncOperation.progress;
if (val == 1)
{
asyncOperation = null;
prgCB = null;
}
};
}