Change component in a gameobject within another gameobject

Thanks for checking out my question! The code in my RTS game is made to take all gameobjects (armyguys) and check if they are inside the box I make with holding down the mouse, if so it will follow on my next mouse press. Now the code:

public void SelectArea ()
{
 GameObject[] Bot = GameObject.FindGameObjectsWithTag("BlueTeam");
 foreach(GameObject Body in Bot)
 {
  if(InRangeOfTargets(Body.transform))
   Body.GetComponent<MineBotAI>().target.GetComponent<Selected>.cantransport = false;
 }
}

As you probably see I’m trying to get a gameobject(target) within another gameobject and then change a public boolean, cantransport. And I get the following error message:

Assets/Scripts/TargetMover.cs(126,71): error CS0119: Expression denotes a method group', where a variable’, value' or type’ was expected

Any suggestion on solutions?

Body.GetComponent()

GetComponent needs an argument, like the name of the other component. What is the name of the other component? Put it there.

Also

target.GetComponent.

is not legal. Again, you need to give it the name of the component to get.

getcomponent isn’t being called right. if you want to find the component cantransport its.

GetComponent<cantransport>().

but even then cantransport i think is a bool.

components aren’t variables they are scripts so it should be something more like.

GetComponent<transportationscript>().cantransport = false;

thats how you access a variable in a script. If you would post your cantransport script it might be helpful if this doesnt do it.

Basically

script transportation

public bool cantransport;


script select area

public void SelectArea ()
{
 GameObject[] Bot = GameObject.FindGameObjectsWithTag("BlueTeam");
 foreach(GameObject Body in Bot)
 {
  if(InRangeOfTargets(Body.transform))
   Body.GetComponent<transportation>().cantransport = false;
 }
}