- Home /
OnSceneLoaded-specifically targeting one scene
Hello I was using OnSceneLoaded(Scene scene, Loadscenemode mode) and was wondering as to how weget this to happen to a specific scene. This currently runs the function everytime I open any scene, so it would be useful to know how to target a specific scene.
@Paul$$anonymous$$evin basically when the game starts you have 2 options single player and multiplayer, I want the game to start running a function immediately when I have switched to the multiplayer scene, problem is that I am having the function also run in the singleplayer screen. So I would like to know how to make the function run only when a specific scene has loaded.
Ow then you should do it something like this . LoadScene$$anonymous$$ode.Additive
Did you try it like that?
// Only specifying the sceneName or sceneBuildIndex will load the Scene with the Single mode Scene$$anonymous$$anager.LoadScene("Single$$anonymous$$ode", LoadScene$$anonymous$$ode.Additive);
It passes the scene that was just loaded as an argument, why not just check the scene's properties to see if it's the one you're interested in?
@TreyH I am a beginner can you please explain that a bit more, how can I check the scenes properties
@Paul$$anonymous$$evin how would loadscenemode.additive help, please explain what loadscenemode.additive does, thank you
LoadScene$$anonymous$$ode.Additive is it adds the scene to the current loaded scenes. If you use LoadScene$$anonymous$$ode.Additive, you leave the current scene open, and load the contents of the additional scene into the current scene. And my bad you should have used loadscenemode.single
ins$$anonymous$$d because you want it like a stage by stage game kind of right?
If you use LoadScene$$anonymous$$ode.Single, you close the current scene, and load the new scene.
Answer by Dragate · Dec 28, 2017 at 07:02 AM
void OnEnable(){
SceneManager.sceneLoaded += OnSceneLoaded;
}
void OnSceneLoaded(Scene scene, LoadSceneMode mode){
if(scene.name.Contains("Multiplayer")){ //something that identifies multiplayer scenes
//execute multiplayer function
}
}