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

nicholasgryczewski
nicholasgryczewski
2,919 Points

My NavMeshAgent isn't working???

Here is my code

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

public class BirdMovement : MonoBehaviour {

[SerializeField]
private Transform target;
private NavMeshAgent birdAgent;
private Animator birdAnimator;
// Use this for initialization
void Start () {
    birdAgent = GetComponent<NavMeshAgent>();
    birdAnimator = GetComnponent<Animator>();

}

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

    //Measure the magnitude of the NavMeshAgent's velocity
    float speed = birdAgent.velocity.magnitude;
    //Pass the velocity to the animator component
    birdAnimator.SetFloat("Speed", speed);
}

}

for some reason I'm getting this error message in my console Assets/Scripts/BirdMovement.cs(9,13): error CS0246: The type or namespace name NavMeshAgent' could not be found. Are you missingUnityEngine.AI' using directive?

Thus, I am not receiving a drop box for Target in the Bird Movement component where I am supposed to drop the player so the bird chases the player.

Any ideas???

2 Answers

nicholasgryczewski
nicholasgryczewski
2,919 Points

I added UnityEngine.AI in the top to fix it. I got another problem though now which I will make a new question for.

Akhilesh N
Akhilesh N
617 Points

May be its this one because i fixed the above one i got an another problem of this kind: Assets/Scripts/BirdMovement.cs(36,19): error CS1061: Type UnityEngine.AI.NavMeshAgent' does not contain a definition forSetFloat' and no extension method SetFloat' of typeUnityEngine.AI.NavMeshAgent' could be found. Are you missing an assembly reference?

Josh Coffy
Josh Coffy
2,215 Points

Yep! It isn't in the video to bring in the UnityEngine.AI. Looks like this needs an update!