I have two 2D Character Controllers in my game from the unity Sample Assets beta package and I want to be able to switch control from one to the other and back with the press of a button and have the camera focus on the new character. The method I came up with was to attach a script to each character meaning when I press a button it disables the controller scripts on one character while enabling them on the other. Here’s the code thus far:
var script;
function Update() {
if(Input.GetKeyDown(KeyCode.P))
script = GetComponent("Platformer2DUserControl");
script.enabled = false;
}
{
if(Input.GetKeyDown(KeyCode.P))
script = GetComponent("PlatformerCharacter2D");
script.enabled = false;
}
I then have the same script attached to my other controller only replacing ‘false’ with ‘true.’ This kinda works but very poorly and with some animation problems. Also I don’t know how to switch back to the previous character controller but pressing the same button. I have no idea how to do the camera. Any help would be really appreciated, thanks!
Ah, I see you are going for The Cave gameplay style by Double Fine. Very nice.
Okay, this may require some changes to your project a bit. Instead of attaching this to your characters, make an empty GameObject and call it a GameManager. Having a GameManager is really great and will be far more efficient to use than if the characters handled the switching themselves. Plus, it’s really flexible! If you use Arrays with your GameManager you could possibly have as many characters as your heart desires. The code I’ve written for you obviously isn’t capable of that, but it’s should be good base to get you going. 
Here’s the one for the GameManager.
var Character1 : Transform = null;
var Character2 : Transform = null;
function Update () {
if(Input.GetKey(KeyCode.N)){
Character1.gameObject.SendMessage("Activate");
Character2.gameObject.SendMessage("Deactivate");
}
if(Input.GetKey(KeyCode.B)){
Character2.gameObject.SendMessage("Activate");
Character1.gameObject.SendMessage("Deactivate");
}
}
Now here’s the code for the Characters. (Pay attention to how I treat the boolean, very important)
var inputEnabled : boolean = false;
// Update is called once per frame
function Update () {
if(inputEnabled == true){
transform.Translate(Vector3.right * 5 * Input.GetAxisRaw("Horizontal") * Time.deltaTime);
transform.Translate(Vector3.up * 5 * Input.GetAxisRaw("Vertical") * Time.deltaTime);
}
}
function Activate(){
inputEnabled =true;
}
function Deactivate(){
inputEnabled =false;
}