Change Character Gender

Hey guys, im trying to change my characters gender in the creation screen. having a bit of trouble…

void Start () {
		if (gendmale){
			//change PlayerPrefab to male
			Debug.Log("gendmale = true");
		}
		else if (gendfemale) {
                    //change PlayerPrefab to female
			Debug.Log("gendfemale = true");
		}
		GameObject pc =Instantiate(PlayerPrefab, Vector3.zero, transform.rotation * Quaternion.Euler (-90,180,0)) as GameObject;

as you can see i have a GameObject variable caleld PlayerPrefab (starts as a male) and buttons (not referenced here) that switch booleans to false and true. If male is true i want PlayerPrefabs model to be changed to the male model and vice versa… how would i do this properly?

1 Answer

1

Just use a second property for the female prefab. Then create a variable which will be assigned the correct prefab, depending on your gendmale variable. In most cases you wont need two bool variables for male AND for female, since there is no third option. :slight_smile:

void Start () {

	GameObject prefab = null;
	
	if (gendfemale)
	{
		//change prefab to FemalePlayerPrefab
		prefab = FemalePlayerPrefab;
	}
	else
	{
		//change prefab to MalePlayerPrefab
		prefab = MalePlayerPrefab;
	}

	GameObject pc =Instantiate(prefab, Vector3.zero, transform.rotation * Quaternion.Euler (-90,180,0)) as GameObject;
}

hey i tried that. i didnt work :(

–

see i put a Debug.Log in so that i could see if the button is firing.. the button is going but the model isnt changing.. :/ [22482-picture+69.png|22482]

–

If you put an Instantiate in Start(), it will only happen once. If you want the preview to change when you click the button, you should instantiate both in Start, and hide (gameObject.SetActive(false)) one at a time when you set the gender boolean, (which you could then save to PlayerPrefs and use to instantiate the correct character in the next scene).

–

Do you understand? The way you have it now, you're expecting the buttons to change the past.

–

But u see my script is very complex and long.. its confusing as if i change it now ill screw it up.. http://pastie.org/private/nonkvx0uubtq7yj7m6hq see

–