Does anybody know how to check if both buttons are pressed?
Where if one button is pressed, it waits for a short time until the other button is pressed before knowing that both buttons are pressed, otherwise, that button press is going to be registered as a single button press.
It’s mainly for timing issues in a mobile game, the buttons used are UI buttons.
Thanks in advance!
@it_master you can use flag ( bool ) to check.
public class Example : MonoBehaviour
{
public Button btn1;
public Button btn2;
bool btn1Pressed = false;
bool btn2Pressed = false;
void Start()
{
btn1.AddListener(MyAction1);
btn2.AddListener(MyAction2);
}
void MyAction2()
{
btn2Pressed = true;
if(btn1Pressed )
{//both pressed
btn1Pressed = btn2Pressed = false;
}
}
void MyAction1()
{
btn1Pressed = true;
if(btn2Pressed )
{//both pressed
btn1Pressed = btn2Pressed = false;
}
}
}