Answers for "navmesh agent unity follow object"

C#
0

navmesh agent unity follow object

using UnityEngine;
   using UnityEngine.AI;
    
    public class MoveToTarget : MonoBehaviour 
    {  
       //Assign in inspector the target that you want to follow
       public Transform target;
       
       void Update() 
       {
          //Move towards target every frame and stay in the NavMesh
          GetComponent<NavMeshAgent>().destination = target.position;
       }
       
    }
Posted by: Guest on February-07-2021

C# Answers by Framework

Browse Popular Code Answers by Language