Blacksmith building logic issue

Hi guys, I am pretty new in Unity.

I wanted to create blacksmith building to reset the equipment, but I am facing some issues.

Equipment has to have 3 attributes but all different in 3 line, however my logic sometimes is giving the same attribute in 2 lines which is the behavior I do not want.

Is there any ways of fixing the issue or any way to simply the logic flow? Here is my code:

public void Awake()
{        
    troopsAtrribute.Add("Infantary Attack");
    troopsAtrribute.Add("Infantary Hp");
    troopsAtrribute.Add("infantary Defense");
    troopsAtrribute.Add("Archer Attack");
    troopsAtrribute.Add("Archer Hp");
    troopsAtrribute.Add("Archer Defense");
    troopsAtrribute.Add("Cavalary Attack");
    troopsAtrribute.Add("Cavalary Hp");
    troopsAtrribute.Add("Cavalary Defense");

}

public void EquipmentReset()
{
    attributesFirst = Random.Range(8f, 15f);
    attributesFirst = (float)System.Math.Round(attributesFirst, 2);
    attributesSecond = Random.Range(8f, 15f);
    attributesSecond = (float)System.Math.Round(attributesSecond, 2);
    attributesThird = Random.Range(8f, 15f);
    attributesThird = (float)System.Math.Round(attributesThird, 2);

    string firstLineAttributes = troopsAtrribute[Random.Range(0, troopsAtrribute.Count)];
    string secondLineAttributes = troopsAtrribute[Random.Range(0, troopsAtrribute.Count)];
    string thirdLineAttributes = troopsAtrribute[Random.Range(0, troopsAtrribute.Count)];
    
    Resetting = true;

    if(Resetting == true)
    {
        if(attributesFirst <= 10)
        {
            firstLine.color = grey;
            firstLine.text = firstLineAttributes + " " + attributesFirst + "%";                
        }
        if(attributesFirst > 10 && attributesFirst <= 12)
        {
            firstLine.color = blue;
            firstLine.text = firstLineAttributes + " " + attributesFirst + "%";
        }
        if(attributesFirst > 12)
        {
            firstLine.color = red;
            firstLine.text = firstLineAttributes + " " + attributesFirst + "%";
        }

        if(firstLineAttributes != secondLineAttributes)
        {
            if (attributesSecond <= 10)
            {
                secondLine.color = grey;
                secondLine.text = secondLineAttributes + " " + attributesSecond + "%";                    
            }
            if (attributesSecond > 10 && attributesSecond <= 12)
            {
                secondLine.color = blue;
                secondLine.text = secondLineAttributes + " " + attributesSecond + "%";
            }
            if (attributesSecond > 12)
            {
                secondLine.color = red;
                secondLine.text = secondLineAttributes + " " + attributesSecond + "%";
            }

        }
        else
        {
            EquipmentReset();
        }
        if (firstLineAttributes != thirdLineAttributes && secondLineAttributes !=thirdLineAttributes )
        {
            if (attributesThird <= 10)
            {
                thirdLine.color = grey;
                thirdLine.text = thirdLineAttributes + " " + attributesThird + "%";                    
            }
            if (attributesThird > 10 && attributesThird <= 12)
            {
                thirdLine.color = blue;
                thirdLine.text = thirdLineAttributes + " " + attributesThird + "%";
            }
            if (attributesThird > 12)
            {
                thirdLine.color = red;
                thirdLine.text = thirdLineAttributes + " " + attributesThird + "%";
            }

        }
        else
        {
           EquipmentReset();
        }
    }
  1. Too much if/else makes program incomprehensible. Get rid 90% of those.
  2. Try to stay away from writing methods that can ever call themselves. This will lead to program crashing sooner or later (freeze due to infinite loop or exceptions because of stack overflow).
  3. If you want to ensure that some semi-random permutations never repeat it’s sometime best to create list of all (reasonably) possible permutations and just remove randomly pick entries from it as you go.
  4. Don’t worry, making sure random entries do not repeat is not a trivial task.

Consider this:

[SerializeField] TroopsAttribute _first;
[SerializeField] Text _firstLine;

[SerializeField] TroopsAttribute _second;
[SerializeField] Text _secondLine;

[SerializeField] TroopsAttribute _third;
[SerializeField] Text _thirdLine;

void Awake ()
{
    EquipmentReset();
}

public void EquipmentReset ()
{
    var pool = CreateNewPool();

    _first = CreateRandomAttribute( pool );
    _second = CreateRandomAttribute( pool );
    _third = CreateRandomAttribute( pool );

    UdpateText( _firstLine , _first );
    UdpateText( _secondLine , _second );
    UdpateText( _thirdLine , _third );
}

static TroopsAttribute CreateRandomAttribute ( List<(TroopsType,StatType)> pool )
{
    UnityEngine.Assertions.Assert.IsTrue( pool.Count!=0 , "pool is empty!" );
    var result = new TroopsAttribute();
    {
        result.Value = Random.Range(8f,15f);
    
        int i = Random.Range( 0 , pool.Count );
        var entry = pool*;
        pool.RemoveAt(i);

        result.Troops = entry.Item1;
        result.Stat = entry.Item2;
    }
    return result;
}

static void UdpateText ( UnityEngine.UI.Text text , TroopsAttribute attribute )
{
    text.text = $"{attribute.Troops} {attribute.Stat} {attribute.Value:0.00}%";

    if( attribute.Value<10f )
    text.color = Color.grey;
    else if( attribute.Value<12f)
    text.color = Color.blue;
    else// >= 12f
    text.color = Color.red;
}

static List<(TroopsType,StatType)> CreateNewPool ()
{
    var pool = new List<(TroopsType,StatType)>();
    List<TroopsType> everyType = new List<TroopsType>( (TroopsType[]) System.Enum.GetValues(typeof(TroopsType)) );
    List<StatType> everyStat = new List<StatType>( (StatType[]) System.Enum.GetValues(typeof(StatType)) );
    for( int indexType=0 ; indexType<everyType.Count ; indexType++ )
    for( int indexStats=0 ; indexStats<everyStat.Count ; indexStats++ )
    pool.Add( ( everyType[indexType] , everyStat[indexStats] ) );
    return pool;
}

public enum TroopsType { Infantary , Archer , Cavalary }
public enum StatType { Attack , Hp , Defense }

[System.Serializable]
public class TroopsAttribute
{
    public TroopsType Troops;
    public StatType Stat;
    public float Value;
}