I am new to Unity Game development and started with some tutorials. I am facing a problem where keystroke inputs from keyboard is not recognized/picked up by unity. I checked some solutions online but am more confused request help.
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Space) == true)
{
Debug.Log("Space key pressed");
myRigidbody.linearVelocity = Vector2.up * FlapStrength;
}
else
Debug.Log("Key Stroke Not Received");
}
Debug:
Key Stroke Not Received
UnityEngine.Debug:Log (object)
Flappy_Bird:Update () (at Assets/Flappy_Bird.cs:22)
Key Stroke Not Received
UnityEngine.Debug:Log (object)
Flappy_Bird:Update () (at Assets/Flappy_Bird.cs:22)
Key Stroke Not Received
UnityEngine.Debug:Log (object)
Flappy_Bird:Update () (at Assets/Flappy_Bird.cs:22)
Key Stroke Not Received
UnityEngine.Debug:Log (object)
Flappy_Bird:Update () (at Assets/Flappy_Bird.cs:22)
I tried to check settings in Input Manager and also reinstalling Unity. Checked for solution here, but didn’t find one which can solve this problem.
Noob is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
21
Make sure that the game window has focus while running.
Clicking into the inspector or elsewhere in the editor will prevent the game window from capturing the input.
Click inside of the game window after pressing play to ensure it has focus.
It would also help your cause to completely remove the else
statement, as to not flood the console with pointless logs. It can be next to impossible to find a single message among thousands of messages. The else statement log doesn’t tell you anything anyway, only the if statement log is relevant.
private void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
Debug.Log($"Space Pressed!");
}
}
1