Performance: Why input drives player interaction
HIGH IMPACT
This concept affects how quickly and smoothly the game responds to player actions, impacting input responsiveness and frame updates.
void Update() {
if (Input.anyKeyDown) {
HandleInput();
}
}
void HandleInput() {
if (Input.GetKeyDown(KeyCode.W)) MoveForward();
else if (Input.GetKeyDown(KeyCode.S)) MoveBackward();
}void Update() {
if (Input.GetKeyDown(KeyCode.W)) {
MoveForward();
}
if (Input.GetKeyDown(KeyCode.S)) {
MoveBackward();
}
// Multiple input checks with heavy logic inside Update
}| Pattern | Input Checks | Frame Delay | Responsiveness | Verdict |
|---|---|---|---|---|
| Multiple heavy input checks in Update | Many per frame | 5-10ms delay | Low, causes input lag | [X] Bad |
| Single input check with event-driven logic | Minimal per frame | Under 2ms delay | High, smooth input | [OK] Good |