docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Tell a NavMeshAgent to Move to a Destination

    You can tell an agent to start calculating a path simply by setting the NavMeshAgent.destination property with the point you want the agent to move to. As soon as the calculation is finished, the agent will automatically move along the path until it reaches its destination. The following code implements a simple class that uses a GameObject to mark the target point which gets assigned to the destination property in the Start function. Note that the script assumes you have already added and configured the NavMeshAgent component from the editor.

        // MoveDestination.cs
        using UnityEngine;
        using UnityEngine.AI;
    
        public class MoveDestination : MonoBehaviour {
    
           public Transform goal;
    
           void Start () {
              NavMeshAgent agent = GetComponent<NavMeshAgent>();
              agent.destination = goal.position;
           }
        }
    
    In This Article
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)