Detect if a button/key was pressed
So I want if a button (space) is pressed it would do another set of action every tick
if(.....) //The space bar was not pressed //do this else // The space var was pressed and it will continue to do this set of actions until the space //do this bar is pressed again
do a set of actions if space was pressed (until its not pressed any more) -
if (Input.Get$$anonymous$$eyDown("space"))
{
set of action
}
do a set of actions if space was not pressed (until its pressed again) -
if (Input.Get$$anonymous$$eyDown("space") == false)
{
set of action
}
do a set of action only once when pressed (there might be a command specifically for that but i have no idea so ill use logic
bool move = Input.Get$$anonymous$$ey("space")
private bool done = false;
if (move == true) && (done == false)
{
set of action
done = true;
}
if (move == false)
{
done = false
}
please correct me if im wrong on smth im kinda new here too
Your answer
![](https://koobas.hobune.stream/wayback/20220612054537im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Im trying to make gameObject move only if specific button is pressed 1 Answer
Simple Button Pressed Question? 1 Answer
Perform Action Only When Button is Pressed (Gamepad with Input System) 1 Answer
Explode on button down? 0 Answers
How to minimize UnityApplication by C# script via click button for WindowsOS. 1 Answer