- Home /
Turn On - off character controller script, is there a way??
I am trying to do my character grab and launch objects and enemies but to do it with enemies I need to turn off, and on again character controller, is there a way (js) ?
Thanks in advance!
Do you mean the CharacterController component or a script that controls your character? They are two separate things.
I mean the CharacterController component, is there a way to turn it On or Off?
the problem is: I have a character and one of his actions is to pickup things and enemies and launch. With things my code works well, but since the enemies have the CharacterController component, they cannot act as common rigidbodies when they are grabbed and launched, just if I remove the component, is there a way to cancel the CharacterController effects? (turn on/off) ??
Answer by Anxo · Jun 19, 2011 at 01:57 PM
function Update () {
if(Input.GetButtonDown("Fire1"))
{
var myController : CharacterController = GetComponent(CharacterController);
Destroy(myController);
}
if(Input.GetButtonDown("Fire2"))
{
gameObject.AddComponent(CharacterController);
}
}
Answer by ant123 · Jun 19, 2011 at 12:43 PM
same question
WELL!!!! obviously when i mentioned i had the same question, there was an HT$$anonymous$$L error on this website, because the first post was displayed, with no answered ander it, that is wy i wrote "same question"... in fact i noticed alot of pages where i click and only the first post is displayed. will see why. besides my high contrast web page setting might make the comment/answer system less visible and i am a noob. thanks
Answer by tikot · Sep 08, 2012 at 10:31 PM
The bast way to do this is in Character script if using unity CharacterMotor script
In CharacterMotor.js Change
var canControl : boolean = true;
To
static var canControl : boolean = true;
Use
//turn character off
CharacterMotor.canControl = false;
//turn character on
CharacterMotor.canControl = ture;