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:
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;
}
}
}