Changing player model with keypress.

Hello,

I am having trouble coming up with the script for when the player presses a key, the current character model will switch to another model.

I am using javascript.

if (Input.GetButton ("1")) {
 //player switches character
}

I have the 3 models in the hierarchy but I am not sure how I would call on them to switch when the key is pressed.

Thanks for any help and time taken.

I have a feeling that this may get a bit more complicated then you currently suspect if these are animated or moving objects etc... but for what your asking you'll need to destroy/disable the current model and and instantiate/enable the next one. The simplest option being:

currentModel.SetActiveRecursively(false);

newModel.SetActiveRecursively(true);

Here's a little script the might work:

var modelOne = GameObject.Find("Player1");
var modelTwo = GameObject.Find("Player2");
var modelThree = GameObject.Find("Player3");

if (Input.GetKeyDown ("1")) {
 modelOne.SetActiveRecursively(true);
 modelTwo.SetActiveRecursively(false);
 modelThree.SetActiveRecursively(false);
}
else if (Input.GetKeyDown ("2")) {
 modelOne.SetActiveRecursively(false);
 modelTwo.SetActiveRecursively(true);
 modelThree.SetActiveRecursively(false);
}
else if (Input.GetKeyDown ("3")) {
 modelOne.SetActiveRecursively(false);
 modelTwo.SetActiveRecursively(false);
 modelThree.SetActiveRecursively(true);
}

Hope this will help you out!

Hi Alan just wondering if you could link me to demize2010 player organizing if possible.

cheers