Search code examples
c#unity-game-enginenavigationaugmented-realityvuforia

Is there any solution for "destination" error with NavMeshAgent in Unity?


I'm working on "Indoor Navigation" using Vuforia in unity. I have scanned the map using "Vuforia Area Target Creator" and import area targets to Unity Project, then I have merged mulitple area targets as one area target, then I have Created NavMesh and NavMesh Agent, then I want to test if the NavMeshAgent move to destination or not. I'm following Unity Manual: https://docs.unity3d.com/Manual/nav-MoveToDestination.html

When I wrote this script, I get this error: Error

My Script:

// MoveTo.cs
using UnityEngine;
using UnityEngine.AI;
public class MoveTo : MonoBehaviour {
   
   public Transform goal;
   
   void Start () {
      NavMeshAgent agent = GetComponent<NavMeshAgent>();
      agent.destination = goal.position; 
   }
}

I also searched on Youtube, I found that someone wrote the same code for his game and working with him, What's the problem ??

Can any one help me in this ?


Solution

  • private void Start()
    {
        NavMeshAgent agent = GetComponent<NavMeshAgent>();
        agent.SetDestination(goal.position);
    }
    

    if you want to set your agent destination to the target than change your code like upon code.