Question by
DreifachWolf · Apr 23, 2020 at 02:02 PM ·
keyboard input
How can i disable KEyboard button
Hey there. I have a simple question. I followed a movement Tutorial and just wanted to change some stuff. I especially wanted to change that you cant move left right and back while jumping but my Problem is that I don't know how to disable Keys. It would be great if anybody could help me change the code so that it works
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public CharacterController controller;
public float WalkSpeed = 12f;
public Transform GroundCheck;
public float GroundDistance = 0.4f;
public LayerMask GroundMask;
Vector3 Velocity;
bool IsGrounded;
public float Gravity = -9.81f;
public float JumpHeight = 3f;
void Update()
{
IsGrounded = Physics.CheckSphere(GroundCheck.position, GroundDistance, GroundMask);
if(IsGrounded && Velocity.y < 0)
{
Velocity.y = -2f;
}
float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");
Vector3 move = transform.right * x + transform.forward * z;
controller.Move(move * WalkSpeed * Time.deltaTime);
Velocity.y += Gravity * Time.deltaTime;
controller.Move(Velocity * Time.deltaTime);
if(Input.GetButtonDown("Jump") && IsGrounded)
{
Velocity.y = Mathf.Sqrt(JumpHeight * -2f * Gravity);
}
if(IsGrounded == false)
{
Input.GetButtonDown(KeyCode.A);
}
}
}
greetings
Ruven
Comment