I'm having trouble accessing the component NavMeshAgent (via script).

So what I’m trying to do is place an object into the NavMeshAgent.destination, where I’m stuck
is that I don’t know what to type after GetComponent (“NavMeshAgent”).destination = ???

When I was sending the scripted object to a destination position I could simply type
transform.GetComponent (“NavMeshAgent”).destination = target.position

But now that I’m trying to determine the scripted object’s destination position I’m not getting a response when I type the same thing. So I checked what the destination looks like with Debug.Log and it showed (X , Y , Z) coordinates
like so: (984.3, -4.3, -214.5)
So I tried typing .destination == Vector3(984.3, -4.3, -214.5) but still nothing happened.

Could someone please explain what I’m doing wrong


var target : Transform;

function Update() {

if (GetComponent ("NavMeshAgent")**.destination == __target.position)__** {

Debug.Log ("destination is now target");
}
Debug.Log (GetComponent ("NavMeshAgent").destination); // checking what destination parameter looks like.
}

First of all, get rid of all the different colors and styles in your post. Really hard to read.

Store the NavMeshAgent in a variable. GetComponent is slow.

var agent: NavMeshAgent;

function Start()
{
     agent = GetComponent(NavMeshAgent);
}

Also, you are comparing three floats with three diffrent floats now, which is very likely to not work properly. You should check the distance between the two points and if it is close to zero. (See Vector3.Distance)

Also, use SetDestination to set the destination: