Hi, I’ve got a question about how this for loop is executed in the game loop. Sorry for the following message, it might be confusing, but I’ll give some context, so it would be easier to understand my question:
Every game has a game loop, which is executed step-by-step, line by line every frame. In unity it’s the Update method. So if we have 60 fps, update is called 60 times per second and is executed from the first till the last line. The game does not stop on the if statement waiting for the player to press the button, it just checks whether it was pressed in this particular frame, right? So if I understand this conception correctly, then for loop is run 3 times per frame (if for instance we have 3 elements in the array), and the game checks for the key code to be received from hardware in that frame. If it wasn’t, the execution just moves on. Is there a slight possibility, that I pressed key 2 in frame 43, but the for loop is on it’s 3rd iteration in frame 43, and it missed my key 2 pressed and checks for the key 3 already? Is the input method is somehow executed in parallel, or it remembers what keys were pressed in previous frames and executes them in following frames?
Second question is easier, do I understand correctly that this piece of code will not work if I want player to press E, or W, or Enter keys? They have different codes that can’t be “reached” by just incrementing key 1 code? What would be your proposal for implementing such input? I’m thinking only about if else statements, but that would cause the bug to return.
Thank you!