The script needs to derive from MonoBehaviour

hello i’m new to this kind of stuff and i was following a tutorial to go learning but when adding the script gives me the error mentioned in the title. How can i fix it?

4829018--463421--Screenshot_1.png

It’s hard to read because it’s unformatted but at first glance you are not using the correct names for methods etc.
It’s Input.GetKey not getkey, Vector2 not vector2 etc.

  1. Make sure, your script is called pacman. Exactly the sames as class name, which is derived from MonoBehaviour.
    That also means same upper/lower cases.

  2. Format your code accordingly. Keep correct indentations.

  3. This question belongs to Scripting forum section and probably even Getting Started.

  4. Next time, copy code to forum.

  5. When pasting code please read how ** Using code tags properly **

2 Likes

Line 32 ends in a comma, where it should be a semicolon.

You should be using a code editor like Visual Studio which points out these kinds of errors as soon as they are typed.

Yeah, as mentioned above, there are a ton of things on this script that will cause compilation errors.

And funnily enough, the MonoBehavior one you’ve mentioned here isn’t actually one of these compilation errors.
Your script does correctly derive from MonoBehavior; it just doesn’t do… anything else correctly.

From the screenshot you posted here, it looks like you’re using Visual Studio, and Visual Studio should be screaming at you with errors here.

1 Like