instantiating player to different scenes
i'm trying to put together a simple Character Creation screen, when create button is clicked a GUI pops up with 3 different characters depending on which you choose it will be instantiated into the scene, with the ability to create more than one character. so you can have 3 animated instantiated objects to pull into the next scene(world) depending on which character you want to play. think of the diablo 2 character selection screen. or MuOnline here is an image of what im trying to achieve.
Answer by nikescar · Sep 24, 2012 at 07:18 PM
You could have a public static variable that the character's prefab name is assigned to.
Something like this in your character select screen script:
public static GameObject selectedCharacter;
public GameObject character1; // drag character prefabs here in the inspector
public GameObject character2;
public GameObject character3;
void OnGUI()
{
if (GUI.Button(Rect(10,10,50,50),"Character 1"))
{
selectedCharacter = character1;
// Put instantiate code here for display in the selection screen
}
if (GUI.Button(Rect(10,35,50,50),"Character 2"))
{
selectedCharacter = character2;
// Put instantiate code here
}
if (GUI.Button(Rect(10,60,50,50),"Character 3"))
{
selectedCharacter = character3;
// Put instantiate code here
}
}
Then in your level loading script you would access selectedCharacter by using the script/class name first and then selectedCharacter. Kinda like this:
Instantiate (CharacterSelectScreen.selectedCharacter, Vector3.zero, Quaternion.identity);
im getting an error; "You can only call GUI functions from inside OnGUI.
I'm still shaky on the concept, where do I exactly out the instantiate class ? @nikescar
You can also use dontdestroyonload method.
http://docs.unity3d.com/ScriptReference/Object.DontDestroyOnLoad.html
Your answer
Follow this Question
Related Questions
Character selection 0 Answers
Plane character selector unity problem 0 Answers
How do I save a previously bought characters in my Game? 0 Answers
Array of Texts that change dynamic on selected character 0 Answers
I have my animations created. Now what? 0 Answers