- Home /
void Update() if (Input.GetKeyDown(KeyCode.LeftShift)) Debug.Log("ShiftPressed"); Don't work
So, I have issues with the shift key in a scrip and did manage to remove most of the logic to just this line that won't produce a console log and I can't find any reason for it not to work.
void Update() if (Input.GetKeyDown(KeyCode.LeftShift)) Debug.Log("ShiftPressed");
Hey,
Just to confirm, you used { } in your actual code? The snippet in your description doesnt have them.
Paste this: void Update() { if(Input.GetKeyDown(KeyCode.LeftShift)) { Debug.Log("Left Shift Pressed"); } }
That shouldn't be a problem since the C# syntax considers one line commands after an if statement as if they were inside the curly brackets. Now the Update method missing the curly brackets is another case, though that would prevent Unity from running the game at all so I suppose they simpli got omitted somewhere along the route.
For the actual problem, I am not sure what could be wrong. Does everything else in the code execute properly? Have you tried placing the debug before or after the if?
Answer by kuba86699 · Oct 19, 2021 at 10:01 AM
I do not know how you have it exactly written in the code and I do not know if you are still looking for a solution to this problem, but write it like this
void Update() {
if (Input.GetKeyDown(KeyCode.LeftShift)) Debug.Log("ShiftPressed");
}
works correctly