[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) ??

1 Answer

1

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 mine was selection char, or customization.. ok thanks bompi88 !! u help me out, i'll try it ! :)