Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question weird error "key.code does not contain a definition for shift"

Discussion in 'Input System' started by TheGrayNinja, Nov 22, 2023.

  1. TheGrayNinja

    TheGrayNinja

    Joined:
    Nov 21, 2023
    Posts:
    1
    I'm trying to add sprinting to my game but for some reason it say's shift, (the input i want to use to sprint) wont work cus its not in "key.code", can anybody help?

    (this is my movement/sprinting/jumping code)
    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4. public class movement : MonoBehaviour {
    5.     public float playerSpeed;
    6.     public float sprintSpeed = 4f;
    7.     public float walkSpeed = 2f;
    8.     public float mouseSensitivity = 2f;
    9.     public float jumpHeight = 3f;
    10.     private bool isMoving = false;
    11.     private bool isSprinting =false;
    12.     private float yRot;
    13.     private Animator anim;
    14.     private Rigidbody rigidBody;
    15.     // Use this for initialization
    16.     void Start () {
    17.          rb = GetComponent<Rigidbody>();
    18.         speed = 10f;
    19.         playerSpeed = walkSpeed;
    20.         anim = GetComponent<Animator>();
    21.         rigidBody = GetComponent<Rigidbody>();
    22.     }
    23.     // Update is called once per frame
    24.     void Update () {
    25.  
    26. float moveHorizontal = Input.GetAxis("Horizontal");
    27.         float moveVertical = Input.GetAxis("Vertical");
    28.  
    29.         Vector3 movementSide = transform.right * moveHorizontal;
    30.  
    31.         Vector3 movementForward = transform.forward * moveVertical;
    32.  
    33.         rb.AddForce(movementSide * speed);
    34.         rb.AddForce(movementForward * speed);
    35.  
    36.  
    37.  
    38.  
    39.  
    40.  
    41.  
    42.  
    43.         yRot += Input.GetAxis("Mouse X") * mouseSensitivity;
    44.         transform.localEulerAngles = new Vector3(transform.localEulerAngles.x, yRot, transform.localEulerAngles.z);
    45.         isMoving = false;
    46.         if (Input.GetAxisRaw("Horizontal") > 0.5f || Input.GetAxisRaw("Horizontal") < -0.5f)
    47.         {
    48.             //transform.Translate(Vector3.right * Input.GetAxis("Horizontal") * playerSpeed);
    49.             rigidBody.velocity += transform.right * Input.GetAxisRaw("Horizontal") * playerSpeed;
    50.             isMoving = true;
    51.         }
    52.         if (Input.GetAxisRaw("Vertical") > 0.5f || Input.GetAxisRaw("Vertical") < -0.5f)
    53.         {
    54.             //transform.Translate(Vector3.forward * Input.GetAxis("Vertical") * playerSpeed);
    55.             rigidBody.velocity += transform.forward * Input.GetAxisRaw("Vertical") * playerSpeed;
    56.             isMoving = true;
    57.         }
    58.         if (Input.GetKeyDown(KeyCode.Space))
    59.         {
    60.             transform.Translate(Vector3.up * jumpHeight);
    61.         }
    62.         if (Input.GetKeyDown(KeyCode.Shift))
    63.         { if (Input.GetAxisRaw("Sprint") > 0f)
    64.         {
    65.             playerSpeed = sprintSpeed;
    66.             isSprinting = true;
    67.         }else if (Input.GetAxisRaw("Sprint") < 1f)
    68.         {
    69.             playerSpeed = walkSpeed;
    70.             isSprinting = false;
    71.         }
    72.         }
    73.      
    74.         anim.SetBool("isMoving", isMoving);
    75.         anim.SetBool("isSprinting", isSprinting);
    76.     }
    77.  
    78.     public float speed;
    79.  
    80.     private Rigidbody rb;
    81.  
    82.  
    83.  
    84.  
    85.  
    86. }
     
  2. APSchmidt

    APSchmidt

    Joined:
    Oct 31, 2023
    Posts:
    249