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 trialnicholasgryczewski
2,919 PointsMy 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 missing
UnityEngine.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
2,919 PointsI added UnityEngine.AI in the top to fix it. I got another problem though now which I will make a new question for.
Josh Coffy
2,215 PointsYep! It isn't in the video to bring in the UnityEngine.AI. Looks like this needs an update!
Akhilesh N
617 PointsAkhilesh N
617 PointsMay 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 for
SetFloat' and no extension methodSetFloat' of type
UnityEngine.AI.NavMeshAgent' could be found. Are you missing an assembly reference?