How to access multiple scripts with different names (with same beginning)

Hi everyone,
I will have several gameobjects (say gameobjects Goal1- Goal4) with the aim to interact with each differently in a given order I load using a subjectspecific .txt file.
Now I found a solution:

// in this void, the trialscripts of each object are started in an order based on the input from the inputFile. If the trialCounter exceeds the number of trials, the game is ended. 
public void Trials()
{
    int[] configValuesArrayTask = GetComponent<readFileTask>().ReadFileTask();
    trialCounter = trialCounter + 1;

    responseKeyCount = 0;
    taskTextKeyCount = 0;
    pauseKeyCount = 0;
    pulseNumber = 0;

    if (trialCounter > numbTrials)
    {
        end();
    }
    else
    {
        if (configValuesArrayTask[0] == trialCounter)
        {
            defineTaskGoal1.enabled = true;
            Goal1.GetComponent<defineTaskGoal1>().StartGoal1();
        }

        else if (configValuesArrayTask[1] == trialCounter)
        {
            defineTaskGoal2.enabled = true;
            Goal2.GetComponent<defineTaskGoal2>().StartGoal2();
        }

        else if (configValuesArrayTask[2] == trialCounter)
        {
            defineTaskGoal3.enabled = true;
            Goal3.GetComponent<defineTaskGoal3>().StartGoal3();
        }

        else if (configValuesArrayTask[3] == trialCounter)
        {
            defineTaskGoal4.enabled = true;
            Goal4.GetComponent<defineTaskGoal4>().StartGoal4();
        }
    }
}

However, in the final version, I want to have 3 times 24 GameObjects (hence a txt file where 72 columns indicate the order of interaction). So I am trying to automize this using a for loop instead of writing 72 if statements.
This works fine with loading all gameobjects into an array, but I cannot “individualize” the accessing of the scripts on each game object (defineTaskGoalX) and the public voids in each script (StartGoalX())

// in this void, the trialscripts of each object are started in an order based on the input from the inputFile. If the trialCounter exceeds the number of trials, the game is ended. 
public void Trials()
{
    int[] configValuesArrayTask = GetComponent<readFileTask>().ReadFileTask();
    trialCounter = trialCounter + 1;

    responseKeyCount = 0;
    taskTextKeyCount = 0;
    pauseKeyCount = 0;
    pulseNumber = 0;

    if (trialCounter > numbTrials)
    {
        end();
    }
    else
    {

        GameObject[] goalObjects;
        goalObjects = GameObject.FindGameObjectsWithTag("Tag1").OrderBy(go => go.name).ToArray(); ;

        foreach (GameObject goalObject in goalObjects)
        {
            Debug.Log(goalObject);
        }

        for (var i = 0; i < goalObjects.Length; i++)
        {

    defineTaskScript = goalObjects_.GetComponent<defineTaskGoal*>();_

if (configValuesArrayTask[0] == trialCounter)
{
defineTaskScript.enabled = true;
goalObjects_.GetComponent<defineTaskGoal*>().StartGoal*();_
}
}
}
}
Stars mark the points where I dont know how to reference them (basically, in other programming languages, “*” would actually help in this case.)

You can use interfaces. Try something like:

public interface IGoal
{
    void SomeMethod();
    string SomeProperty { get; set; }
}

public class GoalA : IGoal
{
    public string SomeProperty { get; set; }

    public void SomeMethod()
    {
        Console.WriteLine($"{SomeProperty} in Goal A");
    }
}

public class GoalB : IGoal
{
    public string SomeProperty { get; set; }

    public void SomeMethod()
    {
        Console.WriteLine($"{SomeProperty} in Goal B");
    }
}

public class TestClass
{
    public IEnumerable<IGoal> Goals { get; set; } = new List<IGoal> 
    {
        new GoalA { SomeProperty = "Hello" },
        new GoalB { SomeProperty = "Hello again" },
    };

    public void UseGoals()
    {
        foreach(var goal in Goals)
        {
            goal.SomeMethod();
        }
    }
}

The implementation via interface sounds better to me, but if you want to keep most of your code, you could just use the non-generic version of GetComponent (the one without the <>) where you can pass a string instead of a type:

int j = 3;
defineTaskScript = goalObjects*.GetComponent("defineTaskGoal" + j);*

Unity - Scripting API: GameObject.GetComponent

You would have to make your defineTaskGoal and other variables into a list as well.

for(int i=0; i<configValuesArrayTask.Count;i++)
    {
           defineTaskGoal*.enabled = true;*

Goal.GetComponent<defineTaskGoal_>().StartGoal*();
}*

A better way would be to put it all into a class._

Am having a hard time following your explanation. can you please give a bit more context.