Search Unity

Question Enemy not moving

Discussion in 'Navigation' started by Captin_Cactus, Jan 7, 2024.

  1. Captin_Cactus

    Captin_Cactus

    Joined:
    Sep 11, 2023
    Posts:
    9
    Im doing a FPS tutorial, on the NavMesh part, But my enemy isnt moving.Why isnt the enemy moving?
    Ive Baked the scene and all. Everthing is setup according to the tutorial, But still nothing. Here is my code.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.AI;
    5.  
    6. public class EnemyAI : MonoBehaviour
    7. {
    8.     [SerializeField] Transform target;
    9.     NavMeshAgent navMeshAgent;
    10.  
    11.     // Start is called before the first frame update
    12.     void Start()
    13.     {
    14.         navMeshAgent = GetComponent<NavMeshAgent>();
    15.     }
    16.  
    17.     // Update is called once per frame
    18.     void Update()
    19.     {
    20.         navMeshAgent.SetDestination(target.position);
    21.     }
    22. }
    23.