Performance: Keyboard input (GetKey, GetKeyDown)
MEDIUM IMPACT
This concept affects the responsiveness and smoothness of user input handling during gameplay.
void Update() {
if (Input.GetKeyDown(KeyCode.Space)) {
// Action triggered only once when space is pressed
Jump();
}
}void Update() {
if (Input.GetKey(KeyCode.Space)) {
// Action triggered every frame while space is held
Jump();
}
}| Pattern | Input Checks per Frame | Repeated Actions | CPU Load | Verdict |
|---|---|---|---|---|
| Using GetKey for single press | Multiple per frame while key held | Yes | High | [X] Bad |
| Using GetKeyDown for single press | One per key press | No | Low | [OK] Good |