Using components through a coroutine not working

I have this code:

void getOnShip()
{
  boatMove scr = boatAtBase.GetComponent<boatMove>();
  Debug.Log("Get on ship button clicked.");
  GameObject[] navies = GameObject.FindGameObjectsWithTag("Navy");
  boatAtBase.transform.parent = null;
  for (int i = 0; scr.capacity < scr.capacityLimit; i++ )
  {
    sendNavaltoBoat(navies*);*

scr.upCap();
}
}
void sendNavaltoBoat(GameObject nav)
{
Debug.Log(“send to naval called”);
Transform ntf = nav.GetComponent(); // ========= this variable
Rigidbody nrb = nav.GetComponent(); // ========== and this variable
if (ntf.position.x - checkpointOne.position.x > 1 || ntf.position.z - checkpointOne.position.z > 1)
{
Debug.Log(“Attempting to move character”);
ntf.LookAt(checkpointOne);
ntf.rotation*=Quaternion.Euler(0f, 90.646f, 15.063f);
nrb.AddRelativeForce(-100, 0, 0);
StartCoroutine toBoat(ntf, nrb); // ======== into here
}
}
IEnumerator toBoat(Transform chtf, Rigidbody chrb) // ======== to be used here
{
while (ntf.position.x - checkpointOne.position.x > 1 || ntf.position.z - checkpointOne.position.z > 1)
{
yield return new WaitForSeconds(0.1f);
}
}
where I need to get the transform and rigidbody variables I mentioned with comments into the coroutine to be accessed. Every time I try to compile it just points to the “Start Coroutine” line and says regarding “ntf” and “nrb”, “Identifier expected”. What am I missing here? Thanks in advance.

You declared your variables ntf and nrb inside your sendNavaltoBoat method. Those are local variables and only exist inside that method.

However your coroutine toBoat has two parameters. When you start your coroutine you pass (copy) the values of your ntf and nrb variables into those parameters.

Inside your coroutine you have access to those parameters. Those parameters are just like local variables. They only exist inside your coroutine. However you named them differently, namely chtf and chrb. So you probably want to use those inside your coroutine. Of course there is no ntf variable available inside your toBoat coroutine.

Apart from using parameters and local variables, you could have declared the variables in your class instead of creating local variables. Class member variables are accessible to all instance methods. Instance methods are any methods inside a class that are not static and therefore belong to an instance of that class.