Need this translated. Js to C#.

Can anyone translate this I have no idea how to get this to work.

var target : Transform;
function Update()
{
  GetComponent(NavMeshAgent).destination = target.position;
}

public transform target;

void Update()
{
    gameObject.GetComponent<NavMeshAgent>().destination = target.postion;
}

Some corrections from the other answer:

public Transform target;

void Update()
{
GetComponent<NavMeshAgent>().destination = target.position;
}

Since in his example script, using GetComponent itself is fine for him, then the component he is getting is likely already on the same object, so you only need to use GetComponent.

This script should be optimized better though, so you are not doing a GetComponent every frameā€¦

Create a variable for the component as well, and set it in Start().

public Transform target;
private NavMeshAgent navMeshAgent;

void Start()
{
navMeshAgent = GetComponent<NavMeshAgent>();
}

void Update()
{
navMeshAgent.destination = target.position;
}