- Home /
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)
Answer by Mike 3 · Feb 18, 2011 at 07:02 PM
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;
}
Answer by machinew · Feb 18, 2011 at 07:49 PM
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
Answer by Unamine · Feb 18, 2011 at 10:35 PM
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
Answer by machinew · Feb 19, 2011 at 11:01 AM
i just uncheck Character 2 Character Motorin the inspector panel and its work
Thank You Guys
Your answer
Follow this Question
Related Questions
Character controller + animation of different meshes making one character 1 Answer
How can I implement a SimpleMove max speed? 1 Answer
Character Controller Movement With WASD 1 Answer
Issue with Character controller and skin width 2 Answers
New to Unity and have questions about creating a Virtual World 1 Answer