second character controller ???

Hello everybody,

i want a make switchable character controllers and i try something like this

var Character1 : GameObject;

var Character2 : GameObject;

function Update () {

 if(Input.GetKeyDown ("1"))
 Character1.GetComponent(CharacterMotor).enabled = true;
 Character2.GetComponent(CharacterMotor).enabled = false;

 if(Input.GetKeyDown ("2"))
 Character1.GetComponent(CharacterMotor).enabled = false;
 Character2.GetComponent(CharacterMotor).enabled = true;
 }

when i pressedd key 1 two controller move together

but when i pressed key 2 its work perfectly

how can i fix that (thats my firspost sory about everything)

You're missing braces to specify which parts are in the if:

if(Input.GetKeyDown ("1"))
{
    Character1.GetComponent(CharacterMotor).enabled = true;
    Character2.GetComponent(CharacterMotor).enabled = false;
}
if(Input.GetKeyDown ("2"))
{
    Character1.GetComponent(CharacterMotor).enabled = false;
    Character2.GetComponent(CharacterMotor).enabled = true;
}

i have a another little problem when i played the game characters move together i want a make only Character1 is enable i tried

var Character1 : GameObject;
var Character2 : GameObject;
var Chaarcter1Enabled = true;
var Chaarcter2Enabled = false;

how can i fix it ? Thank you again

Try this:

var Character1 : GameObject; var Character2 : GameObject; var isActive1 = false; var isActive2 = false;

function Update () {

if(Input.GetKeyDown ("1") && isActive2 == true || isActive2 == false) { Character1(); }

if(Input.GetKeyDown ("2") && isActive1 == true || isActive1 == false) { Character2(); }

function Character1() { Character1.GetComponent(CharacterMotor).enabled = true; Character2.GetComponent(CharacterMotor).enabled = false; }

function Character2() { Character1.GetComponent(CharacterMotor).enabled = false; Character2.GetComponent(CharacterMotor).enabled = true; }

any questions post here again.

Hope that helps

i just uncheck Character 2 Character Motorin the inspector panel and its work

Thank You Guys