Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Game Development How to Make a Video Game Score, Enemies, and Game State Create Enemy Navigation and AI

Derian McCrea
Derian McCrea
1,370 Points

ERROR:Assets/Scripts/BirdMovment.cs(10,13): error CS0246: The type or namespace name `NavMeshAgent' could not be found.

Hello,

I'm lost.

After writing:


using System.Collections; using System.Collections.Generic; using UnityEngine;

public class BirdMovment : MonoBehaviour {

[SerializeField]
private Transform target;

private NavMeshAgent birdAgent;
private Animator birdAnimator;

// Use this for initialization
void Start () {
    birdAgent = GetComponent<NavMeshAgent>();
    birdAnimator = GetComponent<Animator>();

}

// Update is called once per frame
void Update () {
    // Set the birds destination
    birdAgent.SetDestination(target.position);

    // Measure the magnitude of the nave mesh agents velocity
    float speed = birdAgent.velocity.magnitude;

    // Pass the velocity to the animator componenet
    birdAnimator.SetFloat ("speed", speed);
}

}


I get the error:

Assets/Scripts/BirdMovment.cs(10,13): error CS0246: The type or namespace name NavMeshAgent' could not be found. Are you missingUnityEngine.AI' using directive?

I noticed a pop up for a brief moment when returning to Unity to run the scene, and chose not to add the UnityEngine.AI. But I've looked around on google and I don`t know how to add that back into Unity. Or is that something that can be added? Or is the NavMeshAgent the issue?

Any help is much appreciated!

2 Answers

Seth Kroger
Seth Kroger
56,413 Points

You can add another using statement, using UnityEngine.AI; just below the others.

Derian McCrea
Derian McCrea
1,370 Points

Ohhh really! Hey it worked! Thanks so much Seth that's huge!