Unity it does not recognize the keyCode

Hello I have a problem, when I am writing a movement scrip in Unity it does not recognize the keyCode, it tells me that it does not exist. I have already tried to create the project from 0, restart unity and visual studio code, but it still does not work.
In the same way the visual studio plugin does not suggest me the “codes” as input or the keyCode and I have to write all the code by hand.

I attach a photo of the code.

Did you try

GetKeyDown

?

This is a simply capitalization error. In C# everything has to be capitalized correctly, as it is a case-sensitive language.

keyCode should be KeyCode

Part of your problem is that your Visual Studio Code is not properly configured to work with Unity, and is not showing you errors or giving you suggestions.

See this to configure it:

1 Like

Yes the left arrow code is wrong, it should be KeyCode but the right arrow is correct, that one should work. And it should also be GetKeyDown .

No, it should not. GetKeyDown would definitely be wrong here ^^. He wants to move as long as the key is held down and he’s using Time.deltaTime in the calculation. So the code inside the if body has to run every frame while the key is held down. GetKeyDown would not make any sense here.