Instantiate after loading scene
I just need a script that instantiate a gameobject after a scene is loaded.
And why don't OnLevelWasLoaded and Instantiate work for you...?
The script is wrote in a public function that is called when the button "Create player" is clicked. So I need to write the code in the function.
public void CreatePlayer()
{
if (isWarriorClass == true || is$$anonymous$$ageClass == true || isArcherClass == true)
{
Scene$$anonymous$$anager.LoadScene("scene_main");
// Instantiate player after scene loaded
}
}
$$anonymous$$oved to the help room.
Please watch and understand this tutorial, it's one of the most important things to understand if your game has more than one scene.
https://unity3d.com/learn/tutorials/topics/scripting/persistence-saving-and-loading-data
Think about this .... you're going to be calling this each time you change scenes so it makes sense to build a function to do it. What you'll need is to create your character data when you generate the character.
Then call the function to load a new scene, pass it an int (the scene index).
Let's say we pass it 1 and we're now in the function...
If you save data between scenes then write out that data (if you store your players current settings in your DontDestroyOnLoad Game$$anonymous$$aster file you can skip this).
Load the new scene (scene 1).
Instantiate your character.
If you save data between scenes load that character data.
So now you have a scene loader and all you have to do is tell it which scene and it'll recreate your character when the scene loads. Regardless of which scene, although you wouldn't call that function for, say, starting a new game from scratch.
Thanks now I understand but now I have another problem. Could you please read this post and help me? http://answers.unity3d.com/questions/1202545/save-and-load-serialization-problem.html
Your answer
Follow this Question
Related Questions
Saving an image's state 2 Answers
Scene doesn't work 1 Answer
How can i get a script of a non instantiate prefab? 2 Answers
Get current scene number 3 Answers
Basic Unity: Can someone explain the referencing and instantiation process? 1 Answer