well as you see I want this… when pressing Ctrl make height=2 > height=1 ( Crouch)
I used get component but I don’t know what to do cause it’s not script… thnx!
Not sure what you meant by using get component but you are able to access the character controller through getComponent
try
CharacterController controller = GetComponent();
if(Input.GetKeyDown(KeyCode.LeftControl))
{
controller.height = 1;
}
ok i constructed a cube and attached a character controller to it with a height of 2
and then i attached a script called character that adjusts theheight when left ctrl is pressed the code was:
public class Character : MonoBehaviour {
CharacterController controller;
// Use this for initialization
void Start () {
controller = GetComponent<CharacterController>();
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown(KeyCode.LeftControl))
{
if (controller.height == 2)
controller.height = 1;
else
controller.height = 2;
}
}
}
thnx man … I used this :
if (Input.GetKeyDown(KeyCode.LeftControl))
{
if (controller.height == 2)
controller.height = 1.8f;
else
controller.height = 2;
}
if (Input.GetKeyUp(KeyCode.LeftControl))
{
if (controller.height == 1.8f)
controller.height = 2;
else
controller.height = 1.8f;
…
but there is another problem… when I crouch then get Up … the collider will get over terrain so the camera goes under terrain and fall… IDK what should I do!