navimeshと言うものを覚えたのですが、どうしてもゴールの再設定が分かりません・・・

{
public Transform goal;
public Transform goal2;
Vector3 start;

void Start()
{
// 最初の位置を覚えておく
start = transform.position;
// NavMeshAgentを取得して
var agent = GetComponent<UnityEngine.AI.NavMeshAgent>();

// ゴールを設定。
agent.destination = goal.position;
}

void OnTriggerEnter(Collider other)
{
if (other.tag == "goal") { agent.destination = goal2.position; }
}
}

衝突判定の部分のagentにエラー出るんですが、何故コレはだめなんでしょうか?他に書き方があるのでしょうか・・・?