Search Unity

Need help with this Script says that the name 'keyboard' does not exist in the current context

Discussion in 'Editor & General Support' started by devonmuhammad968, Dec 17, 2019.

  1. devonmuhammad968

    devonmuhammad968

    Joined:
    Sep 30, 2018
    Posts:
    41
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class PlayerMove : MonoBehaviour
    {

    [SerializeField] private float movementSpeed = 5f;

    private void Update() => move();


    private void move()
    {
    Vector3 movement = new Vector3();

    if (keyboard.current.wKey.isPressed) { movement.y += 1; }
    if (keyboard.current.aKey.isPressed) { movement.x -= 1; }
    if (keyboard.current.sKey.isPressed) { movement.y -= 1; }
    if (keyboard.current.dKey.isPressed) { movement.x += 1; }

    movement.Normalize();

    transform.Translate(movement * movementSpeed * Time.deltaTime);
    }

    }
     
  2. EyeDev44

    EyeDev44

    Joined:
    Apr 8, 2017
    Posts:
    149
    Same S***
     
  3. - make sure the new Input System is installed
    - learn that C# is case sensitive and make sure you're writing Keyboard.current instead of keyboard.current.
     
  4. EyeDev44

    EyeDev44

    Joined:
    Apr 8, 2017
    Posts:
    149
    It was installed and I reloaded the project. I vscode which runs with intellisense. It underlined even just "Keyboard" as an error.
     
    yangcaitianye1911 likes this.
  5. vs.
    Which one then? Because the poster, whose post you hijacked was mistyping Keyboard. In the first post it is keyboard everywhere.
     
    twicejiggled likes this.
  6. Tarzhan

    Tarzhan

    Joined:
    Jan 20, 2021
    Posts:
    1
    Howdy. I had this problem and solved it by adding: (using UnityEngine.InputSystem; ) to the top of the script. Which the original poster also didn't do. ^^
    There is quite a bit of garbled info on this topic right now.
    Maybe this will help someone.