GetComponent invalid in given context

,

here is the full error


and here is my code

i really dont know what to do ive been messing with it for the last 2 hours. im on the unity rpg course and cannot get the animation to go because the error wont go away. from what i have seen everything is correct.

Hi Ryan,

That’s probably an issue with Visual Studio, not with your code. See the “wrong” colour of MonoBehaviour. It should have the same colour as your class name.

Please try the following suggestions:

  1. Restart Unity and VS.
  2. Is Visual Studio selected as your External Script Editor in Unity (Edit > Preferences > External Tools)?
  3. Are the Unity development tools installed in VS (Tools > Extensions and Updates)? If they are not installed, go to Tools > Get Tools and Features.
  4. Please check if your scripts are included in the project in Visual Studio. Open the Solution Explorer with Ctrl + Alt + L. A dotted icon indicates that the object is not included. If that’s the case, do the following:

  1. Reboot your PC.
  2. Close both Unity and VS. Go to your project folder and delete all sln and csproj files. Then start Unity again, double click on the script file inside your Assets folder in Unity.
  3. Try to update VS.
  4. Try to update Unity.

Did any of these fix the issue for you?

Yea, I fixed it. It was that I was missing () next to something I’m pretty sure

Good job! :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms