Quantcast
Channel: Answers for "Detecting if 2 Buttons are pressed at the same time"
Viewing all articles
Browse latest Browse all 6

Answer by Baste

$
0
0
A big question here is "why?". You usually want to allow the player to press several buttons at once. Also, GetButtonDown only registers on the frame the button is pressed - which means that two of them being true only happens if the player manages to press them approximately at the same time. That being said, this is not very difficult to code up: bool rightPressed = Input.GetKey(KeyCode.RightArrow); bool leftPressed = Input.GetKey(KeyCode.LeftArrow); bool upPressed = Input.GetKey(KeyCode.UpArrow); bool downPressed = Input.GetKey(KeyCode.DownArrow); int numPressed = 0; if (rightPressed) numPressed++; if (leftPressed) numPressed++; if (upPressed) numPressed++; if (downPressed) numPressed++; if (numPressed == 1) { if (upPressed) { MoveUp(); } ... }

Viewing all articles
Browse latest Browse all 6

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>