Input.GetKey seems not to be triggering

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class PlayerController : MonoBehaviour

{

    Rigidbody2D rb2d;

    [SerializeField] float torqueAmount =1f ;

    // Start is called before the first frame update

    void Start()

    {

        Debug.Log("Get Component");

        rb2d = GetComponent<Rigidbody2D>();

    }

    // Update is called once per frame

    void Update()

    {

        if(Input.GetKey(KeyCode.LeftArrow)) // Input.GetKey(KeyCode.LeftArrow)

        {

            Debug.Log("Hello");  

            rb2d.AddTorque(torqueAmount);

        }

    }

}

When changing to true I can prove the update method is running, but having the input.getKey I don’t get any return when pressing the left key.

Unity Version
2021.1.23f1 Personal

1 Like

Hi,

Which left arrow key did you press? The one of the 4 arrow keys or the one of the numpad? Test another keycode, maybe KeyCode.Q, to see if the problem occurs with other keys as well.

Not sure what happened. I had the script associated (I know this as I earlier put a debug.log in the update method on each frame and for sure we had the script connected) but I forgot to save my project (My script was saved) I readded everything (Great practice though!) got to the same point and… it worked. Not sure what I did differently the second time and I’ll never know. But didn’t even think of the q key for debug. I feel silly as I work in a troubleshooting tech role on servers. Should have seen that one.

Try using " in the brackets.

thanks my issue has been fixed.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms