'Unity input is not working, how to fix it?

this is my script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
         if (Input.GetKeyDown(KeyCode.Space))
             Debug.Log("Spase was pressed");
    }
}

its very simple, I have even tried to change the Debug line to jump command and still the was no respond in the game there why I think it not read my input, do you know how to fix it?



Solution 1:[1]

This should definatelly work.

If it doesn't make sure:

  • You have actually assigned the script on a GameObject as a component
  • That GameObject is active when you trying to press space

Those are the two things i can think of that would make this not work assuming your keyboard (and Space button) is working properly.

Solution 2:[2]

As I was just informed that the braces are not relevant I think another way to maybe solve yourproblem could be to replace

KeyCode.Space

With

"space"

Otherwise you could look into this.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 THK
Solution 2