Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Left Shift not working

Discussion in 'Scripting' started by unity_CJOJGT1T8FJ33g, Apr 2, 2022.

  1. unity_CJOJGT1T8FJ33g

    unity_CJOJGT1T8FJ33g

    Joined:
    Aug 14, 2021
    Posts:
    22
    I'm trying to make crouching mechanic but left shift doesn't work.

    Code:
    Code (CSharp):
    1.         if(Input.GetKey("KeyCode.LeftShift"))
    2.         {
    3.             controller.height = 0.5f;
    4.         }
    5.         else
    6.         {
    7.             controller.height = 1f;
    8.         }
    Here's the error:
    Input Key named: KeyCode.LeftShift is unknown
     
  2. unity_CJOJGT1T8FJ33g

    unity_CJOJGT1T8FJ33g

    Joined:
    Aug 14, 2021
    Posts:
    22
    Sorry wrong code.
    here's the actual one:
    Code (CSharp):
    1.         if(Input.GetKey(KeyCode.LeftShift))
    2.         {
    3.             controller.height = 0.5f;
    4.         }
    5.         else
    6.         {
    7.             controller.height = 1f;
    8.         }
     
  3. Lethn

    Lethn

    Joined:
    May 18, 2015
    Posts:
    1,583
    Are you sure this is 'not working'? Are there any error messages? If there aren't, during runtime and you pressing the left shift key keep an eye on your controller component and see if it's even changing the height number. If it is, it may well just be that you aren't changing it enough to have a noticable effect, crouching is admittedly a fairly annoying mechanic to implement.

    I'm asking because I can't spot anything immediately obvious with the code which means it may well be due to your setup.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,749