- Home /
[Closed]Instantiate object to spesific location
so i want to instantiate an object and place it on spesific position, but when i search on Answers, it comes up with Instantiate() function, it hinder me.. i tried to type Instantiate but no autocomplete, so i think does it ok to use? and here's the part of my code where i use to spawn my character from CharacterSelection scene..
function Awake () {
savedplayer = PlayerPrefs.GetInt("selectedplayer");
playerMale = GameObject.Find("Cube1_M");
playerFemale = GameObject.Find("testchar_F");
if(savedplayer == 0){
}
else if(savedplayer == 1){
playerMale.SetActive(true);
playerFemale.SetActive(false);
gameObject.AddComponent("PlayerStats");
}
else if(savedplayer == 2){
playerMale.SetActive(false);
playerFemale.SetActive(true);
gameObject.AddComponent("PlayerStats");
}
}
so i should change the playerMale.SetActive() and Female, to Instantiate(playerMale, Vector3(0,0,0), Quartenion.identity) ??
Answer by bompi88 · Dec 01, 2013 at 01:02 PM
The script you are posting makes sense if you have a typically scene like a customization of a character etc., but regularly it makes no sense to always have two players in the scene, if you don't want to of course. Then you could have the player to switch between characters etc. whenever he wants, by a click of a button for example. Yeah just switch to:
if(savedplayer == 0){
}
else if(savedplayer == 1){
Instantiate(playerMale, Vector3(0,0,0), Quartenion.identity)
gameObject.AddComponent("PlayerStats");
}
else if(savedplayer == 2){
Instantiate(playerFemale, Vector3(0,0,0), Quartenion.identity)
gameObject.AddComponent("PlayerStats");
}
yeph, the first scene of $$anonymous$$e was selection char, or customization.. ok thanks bompi88 !! u help me out, i'll try it ! :)
Your answer
Follow this Question
Related Questions
Index out of range when trying to spawn objects using spawn location list 1 Answer
Instantiate a random prefab at an objects location 3 Answers
Trying to get a shoot function working in unity using instantiate and it isn't working. 1 Answer
getting GameObject from Array and then instantiating 2 Answers