keycode not working

My speed is not changing at all but when i put print(“test”) in the if statement it will print test before i had: Input.getbutton(fire3) since it was set as the left shift after that i changed to this code:5822974--617032--upload_2020-5-8_21-55-24.png
This is the full code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CharMove : MonoBehaviour
{
    //link the character controller
    public CharacterController controller;
    //set movment speed
    public float speed = 10f;

    Vector3 velocity;
    //set gravity for the player
    public float gravity = -10f;

    //link groundcheck
    public Transform Groundcheck;
    public float GroundDistance = 0.4f;
    public LayerMask Groundmask;
    public float jump = 3f;

    bool isGrounded;

    void Update()
    {

        isGrounded = Physics.CheckSphere(Groundcheck.position, GroundDistance, Groundmask);

        if (isGrounded && velocity.y < 0)
        {
            velocity.y = -2;
        }
        //W +1y S-1y    A-1x D+1x!!!caps H and V!!!
        float x = Input.GetAxis("Horizontal");
        float z = Input.GetAxis("Vertical");

        Vector3 move = transform.right * x + transform.forward * z;

        controller.Move(move * speed * Time.deltaTime);

        velocity.y += gravity * Time.deltaTime;

        controller.Move(velocity * Time.deltaTime);

        if (Input.GetButton("Jump") && isGrounded)
        {
            velocity.y = Mathf.Sqrt(jump * -2f * gravity);
        }

        if (Input.GetKeyDown(KeyCode.LeftShift) && isGrounded){
            speed = 20;
        }
        else
        {
            speed = 10;
        }
    }
}

GetKeyDown is only true for the first frame that the key was pressed.
If you want the if-statement to run while the key is being held, use GetKey instead.

2 Likes

Ok il try it out thanks!