Concatenating Serial.print output

I am using an Arduino Uno as a game input controller for Unity.
I have two buttons and am trying to get three states (buttonA, buttonB, both buttonA+ buttonB)
So far, both buttons work, but Unity does not recognize both buttons being pressed at the same time.

I am trying to create a string with a separator that can then be converted to an array in Unity, so Unity will recognize when both buttons are being pushed, but I don't know how to concatenate both of the Serial.print outputs into a string.

Here is my code...

const int buttonPin01 = 6;
const int buttonPin02 = 7;
int left;
int right;


void setup() {
    Serial.begin(9600);
    
    pinMode(buttonPin01,INPUT);
    pinMode(buttonPin02,INPUT);
    
    digitalWrite(buttonPin01, LOW);
    digitalWrite(buttonPin02, LOW);
}

void loop() {
    if(digitalRead(buttonPin01) == HIGH)
    {
      Serial.print(1);
      Serial.flush();
      delay(20);
    }
    if(digitalRead(buttonPin02) == HIGH)
    {
      Serial.print(2);
      Serial.flush();
      delay(20);
    }
  
}

Thanks for any help!

Why not print "3" when both are pushed?

You would get more useful help on a Unity forum.

I don't know how to concatenate both of the Serial.print outputs into a string.

Just print them one after the other

Serial.print(1);
Serial.print(2);

Need a separator ?

  Serial.print(1);
  Serial.print(",");
  Serial.print(2);

MorganS - Thank you! I didn't realize the Arduino could recognize two inputs at the same time, for some reason I thought it just checked one at a time very quickly. I was able to restructure my code to do exactly what I wanted.

void loop() {
    
    if((digitalRead(buttonPin02) == HIGH)&&(digitalRead(buttonPin01) == HIGH))
    {
    Serial.print(3); 
    Serial.flush();
    delay(20);
    }
    
    else if(digitalRead(buttonPin01) == HIGH)
    {
    Serial.print(1); 
    Serial.flush();
    delay(20);
    }
   
  
    else if(digitalRead(buttonPin02) == HIGH)
    {
    Serial.print(2); 
    Serial.flush();
    delay(20);
    }   
}

Those aren't good tests.
You can read the entire PORT (all 8 pins at once) and make decisions from there, vs reading the pins multiple times.

portRead = PORTD; // capture state of D7 to D0
portRead = (portRead && 0b11000000); // mask off the lower bits that are not used
switch (portRead){
case 0b00000000:
// value 0 actions
break;
case 0b01000000:
// value 1 actions
break;
case 0b10000000;
// value 2 actions
break;
case 0b11000000:
// value 3 actions
break;
}

I didn't realize the Arduino could recognize two inputs at the same time

It can't. But the time interval between the two inputs being read may be short enough to appear to a slow human as happening "at the same time".

NCHacker had this code:

    else if(digitalRead(buttonPin02) == HIGH)

but what else could buttonPin02 be at this point?

Replace that code with:

    else

Because buttons are read more than once, I suppose there is a minuscule chance that a button is read in one state at one time and in another state at another time. It would be better at the beginning to read each button and save its state, or even read the entire port and save the value of these two buttons. Then there would zero chance of a value changing while the decision process is going on.