Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NavMeshAgent in unity not working

I am making a game in unity and it is throwing the error "Failed to create agent because there is no valid NavMesh" and i don't know what the problem is.

Setup Pic

using UnityEngine;
using System.Collections;

public class EnemyMotion : MonoBehaviour {
    public NavMeshAgent agent;
    public Rigidbody rb;
    public GameObject otwt;

    void Start () {
        rb = GetComponent<Rigidbody>();
        agent = GetComponent<NavMeshAgent>();
    }
    void Update () {
        gameObject.transform.Rotate(270, 0, 0);
        agent.SetDestination(otwt.transform.position);
    }
}
like image 963
Marcus Mardis Avatar asked Mar 13 '23 09:03

Marcus Mardis


1 Answers

  • Go to Window -> Navigation.
  • Click on the Bake tab.
  • Click on Bake in the bottom right corner.

This will bake the NavMesh and your NavMeshAgent will now work. Right now you have no NavMesh, so your Agents don't know where they can move/walk.

like image 126
JoRouss Avatar answered Mar 29 '23 11:03

JoRouss