Home > Net >  Unity input is not working, how to fix it?
Unity input is not working, how to fix it?

Time:04-22

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?

CodePudding user response:

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.

CodePudding user response:

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.

CodePudding user response:

It could work if instead of putting

If (Input.GetKeyDown(KeyCode.Space))
    Debug.Log(...)

You type

If (Input.GetKeyDown(KeyCode.Space))
    {
    Debug.Log(...)
    }
  • Related