Search Unity

The script needs to derive from MonoBehaviour

Discussion in 'Getting Started' started by fsafsagfagasgasf, Aug 7, 2019.

  1. fsafsagfagasgasf

    fsafsagfagasgasf

    Joined:
    Aug 7, 2019
    Posts:
    1
    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?
     

    Attached Files:

  2. ibbybn

    ibbybn

    Joined:
    Jan 6, 2017
    Posts:
    193
    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.
     
  3. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,779
    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
     
    Vryken and Joe-Censored like this.
  4. bobisgod234

    bobisgod234

    Joined:
    Nov 15, 2016
    Posts:
    1,042
    Line 32 ends in a comma, where it should be a semicolon.
     
  5. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    You should be using a code editor like Visual Studio which points out these kinds of errors as soon as they are typed.
     
  6. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    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.
     
    Joe-Censored likes this.