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 trialJacob Domina
Courses Plus Student 1,767 PointsBird moves without animation
I followed the coding(Although Unity had to change the MavMeshAgent to Unity.AI.NavMeshAgent) the bird moves but has no animation not a huge deal at the moment since the game still works but could be a problem later on.
Tyler Corum
3,514 PointsThe direct answer to your question is at the bottom. But I am obligated to talk about Michael's sentiments... they are regarding C# as a language. See, without specifying the namespace of the NavMeshAgent, the C# compiler doesn't know where to look. Typing "using UnityEngine.AI;" (not "using Unity.Engine.AI;" -- there is no period between Unity and Engine) at the top of the script is a "shortcut" to the assembly reference.
When you type the using statements, it means that down in your code you don't have to specify with every statement what's going on.
To illustrate, I will use the 2 lines of code that are relevant in this video:
private UnityEngine.AI.NavMeshAgent birdAgent;
birdAgent = GetComponent<UnityEngine.AI.NavMeshAgent>();
...is the same as...
using UnityEngine.AI;
[...]
private NavMeshAgent birdAgent;
birdAgent = GetComponent<NavMeshAgent>();
The latter simply requires the using statement at the top of the script. They are the exact same. One simply requires less effort.
1 Answer
Tyler Corum
3,514 PointsANSWER: Your error is in the line "birdAnimator = GetComponent<Animator>();" Make sure the syntax is exact. The reason this is the error is that the Animator component is responsible for the, you guessed it, animations of the bird. Be cognizant of capital and lower-case letters in C#. It matters.
Keep up the efforts!
Michael Walker
45,428 PointsMichael Walker
45,428 PointsThe changes that Unity makes automatically are sometimes a little too messy for my tastes. Leave the NavMeshAgent the way it is and just make sure you have "using Unity.Engine.AI;" at the top of the script and it will still read everything just fine.