- Home /
Question by
IanHearn · Dec 05, 2016 at 08:43 PM ·
scripting problemif-statements
How can I run an if check only after the first key press?
I want my script to check for the player not holding any movement keys. However, I only want it to run this check once the player has started moving. In other words, I want the script to check when the player has stopped moving, without the if statement being made true before the player has started. I don't even know where to begin with this. Thank you in advance for the help.
Comment
Best Answer
Answer by Cherno · Dec 05, 2016 at 09:06 PM
private bool hasMoved = false
void Update() {
if(hasMoved == false && player has pressed movement keys == true) {
hasMoved = true;
}
if(hasMoved == true && player is pressing movement keys == false) {
hasMoved = false;
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612102114im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
If statement inside FixedUpdate 0 Answers
C#, Problem with If Statements and GO Position Comparisons. 1 Answer
Playing the right animation when running and not running 0 Answers
If statement randomly not working 2 Answers
How to increment score by one, every time player moves the device face down ? 2 Answers