Add 2 Variables to one sentence

So I’m making a game that generates random words, I want these words to add up one another so it can form a random sentence.

 if (test <=40)
 {
 var variable1 = Random.Range(1,3);
 
 if (variable1 == 1)
 {
 result.text = "variable1_text1";
 }
 
 if (variable1 ==2)
 {
 result.text = "variable1_text2";
 }
 
 if (variable ==3)
 {
 result.text = "variable1_text3";
 }
 }
 
 if (test > 40)
 {
 var variable2 = Random.Range(1,2);
 
 if (variable2 == 1)
 {
 result.text = "variable2_text1";
 }
 
 if (variable2 == 2)
 {
 result.text = "variable2_text2";
 }

So when I click the button it outputs “variable1_text2”, when i click on it again i want it adds up “variable2_text1”, so it will be “variable1_text2, variable2_text1”.

You can store the previous text into a string, and use it later like this

  1. First create a private string called “PrevTxt” and leave it empty

    if (test <=40)
    {
    var variable1 = Random.Range(1,3);

       if (variable1 == 1)
       {
           result.text = PrevTxt + "variable2_text2";
           PrevTxt = result.text;
       
       }
    
       if (variable1 ==2)
       {
           result.text = PrevTxt + "variable2_text2";
           PrevTxt = result.text;
       }
    
      if (variable ==3)
       {
           result.text = PrevTxt + "variable2_text2";
           PrevTxt = result.text;
       }
    

    }

    if (test > 40)
    {
    var variable2 = Random.Range(1,2);

       if (variable2 == 1)
       {
           result.text = PrevTxt + "variable2_text2";
           PrevTxt = result.text;
       }
    
       if (variable2 == 2)
       {
           result.text = PrevTxt + "variable2_text2";
           PrevTxt = result.text;
       }