Unity 5 上的 OnLevelWasLoaded 在哪里? [英] Where is OnLevelWasLoaded on Unity 5?
问题描述
在这个新的统一版本中,我认为使用了 SceneManager.但是我找不到如何在场景中加载场景.
In this new unity version, I think SceneManager is used. But I cant find how to do on level was loaded with SceneManager.
老方法:
void OnLevelWasLoaded(){
// do something
}
当我尝试旧方法时,我得到了这个:
When I try the old way I get this:
在 MusicManager 上发现 OnLevelWasLoaded此消息已被弃用,并将在更高版本的 Unity 中删除.将委托添加到 SceneManager.sceneLoaded 以在场景加载完成后获得通知
OnLevelWasLoaded was found on MusicManager This message has been deprecated and will be removed in a later version of Unity. Add a delegate to SceneManager.sceneLoaded instead to get notifications after scene loading has completed
不知道怎么用
SceneManager.sceneLoaded();
不知道要传什么...
推荐答案
您必须将 sceneLoaded
作为事件.
You have to sceneLoaded
as an event.
在Start()
或Awake()
函数中注册sceneLoaded
事件.
Register sceneLoaded
event in the Start()
or Awake()
function.
SceneManager.sceneLoaded += this.OnLoadCallback;
OnLoadCallback
函数将在场景加载时调用.
The OnLoadCallback
function will then be called when scene is loaded.
OnLoadCallback
函数签名:
void OnLoadCallback(Scene scene, LoadSceneMode sceneMode)
{
}
这篇关于Unity 5 上的 OnLevelWasLoaded 在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!