How can I trigger booleans in a specific order?

I have 3 booleans which are each triggered by a different key press setup via the Input settings.

  • When the W or Up Arrow key is pressed, tapW = true
  • When the A of Left Arrow key is pressed, tapA = true
  • If both tapW & tapA are true the third bool, tapAW = true

This is good and all but I would like the tapAW bool to become true only if the A key is pressed first followed by the W key (hence the bool name “tapAW”). At the moment tapAW returns true whether the combination W then A is pressed, or A then W is pressed, and I would like to trigger tapAW only when A is first followed by W. I’ve attached the relevant snippet of my simple script below. How could I do this?

public bool tapW = false;
public bool tapA = false;
public bool tapAW = false;
public bool tapWA = false;

//In the Update function

   if (Input.GetButtonDown ("Walk") && !tapW) {
                 tapW = true;
            }
   if (Input.GetButtonDown ("WalkLeft") && !tapA) {
                 tapA = true;
            }
   if (tapA && tapW) {
                  tapA = false;
                  tapW = false;
                  tapAW = true;
            }

you check the time difference of first and second button pressed then you can solve this problem . . .

You could put the buttons in an array, then search it. Of course, that would get ugly fast if you plan to use more than two keys. Something like this:

ArrayList taps = new ArrayList();

void Update()
{
  tapW = tapA = tapWA = tapAW = false;

  if (Input.GetButtonDown("W"))
    taps.Add('W');
  else if (Input.GetButtonDown("A"))
    taps.Add('A');

  if (taps.Count == 1)
  {
    if (taps[0] == 'W')
      tapW = true;
    else
      tapA = true;
  }
  else if (taps.Count == 2)
  {
    if (taps[0] == 'W' && taps[1] == 'A')
      tapWA = true;
    else
      tapAW = true;
  }
  else if (taps.Count == 3)
    taps.Clear();
}