Changing and setting varriables for a specific object while script is used multiple times

Hello Unity. I am a beginner C# coder. I wanted to access a public boolean for an object that is called HasTask. There are, in my case, 4 objects, and when i press a button, one is randomly “selected” and is given a task. I would like to show you what i have

//this is used by a raycast to instantiate a “GO HERE” indicator

Vector3 vec1 = new Vector3((float)x2, 0, (float)z2);

Instantiate(indicator, vec1 , Quaternion.identity);
//here i send the coordinates for where i want my object to go
SendObject(vec1);
}
}

}
void SendObject(Vector3 to){
//select random object from my pool of objects
System.Random rnd = new System.Random();
int i = rnd.Next(0, objectsTB.Length);
GameObject obj = (GameObject)objectsTB*;*

//here i want to put something like
obj.HasTask = true; / ← HasTask is a public varriable from the other script/
obj.TaskTo = to; /* same for this, TaskTo is a vector3 varraible that i want to pass*/
}
My issue that i cannot call the single script is because i have 4 objects using the same script, so i need to tell a specific script to “go here” and so forth. Please let me know if you need anything else

You don’t say what the name/class of this other script, so as a place holder, I’m going to say the name is ‘Tasking’. Fill in the name as needed. Your code will look something like this:

GameObject obj = (GameObject)objectsTB*;*

Tasking task = obj.GetComponent();
task.HasTask = true;
task.TaskTo = to;
See this link for more information on accessing script other game objects:
[http://docs.unity3d.com/412/Documentation/ScriptReference/index.Accessing_Other_Game_Objects.html][1]
[1]: http://docs.unity3d.com/412/Documentation/ScriptReference/index.Accessing_Other_Game_Objects.html