This script needs to derive from monobehavior

i cant drag the script in because of this it also says that my file is missing the class attribute ‘extensionofnativeclass’ anyone know what this means and how i could fix this?

1 Like

Hi, welcome to the community!

This usually happens because you erased something you shouldn’t have, but can’t be sure unless I see your code.
Be sure to copy/paste your code, this way someone will be able to help.

ok here it is.
void Start()
{

}

// Update is called once per frame
void Update()

{ public int Level { get; private set; }
//game state
int level;

enum Screen { MainMenu, Password, win }
Screen currentscreen = Screen.MainMenu;

public Hacker()
{
}

// Start is called before the first frame update
void Start()
{
    Showmainmenu();
    print("hello " + "world");
}

void Showmainmenu()
{
    Terminal.ClearScreen();

    Terminal.WriteLine("What would you like to hack into?");
    Terminal.WriteLine("press 1 for the local library");
    Terminal.WriteLine("press 2 for the local police station");
    Terminal.WriteLine("enter your choice");
}


void OnUserInput(string input)
{
    runmainmenu(input);
}

void runmainmenu(string input)
{
    if (input == "menu")

        Showmainmenu();

    else if (input == "1")

    {
        Level = 1;
        startgame(1);

    }
    else if (input == "2")
    {
        Level = 2;
        startgame(2);
    }
    else if (input == "007")
    {
        Terminal.WriteLine("please select a level mr bond");
    }
    else
    {

        Terminal.WriteLine("please choose a vaild level");
    }
}

void startgame(int level)
{

    Terminal.WriteLine("you have chosen level " + level);
    Terminal.WriteLine("please enter your password");

}

}

thanks.

Is this all?
If that’s the case you are missing several things that should be on top.
Just want to be sure before making you add something that might not necessarily be the problem.

yes this all what am i missing?

This will take me just a couple of minutes. Be patient please, just looking for a link.

thank you very much :smile:

This link will take you to the Lecture Changes, you can find this link in Udemy in the according lecture, here you can compare your code, you are missing the whole top which is needed. Compare your code with this and see what’s missing, just remember, the red lines are the things that Ben removed, so don’t add them.

I’m also giving you this, you are missing this whole part, replace the green lines with your code.

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Hacker : MonoBehaviour 
{
     //Your Code goes in here.
}

thank you very much

Hope this helps. Have fun with the course!

im sorry
i just found that i already have that code is there any other way?

Let me test your code.

    /*void Start()
    {
    }*/


void Update()

{ /*public int Level { get; private set;*/ }

 /*public Hacker()
    {
    }*/

Remove the green, you have two starts, you can’t have multiple methods with the same name within the same script.

That thing inside the update, don’t know what you were trying to do there, actually, just erase the whole Update method, you’ll not use it in this section.

You have that Hacker method that does nothing and returns nothing, erase it.

You’ll also need to change your int level variable name to “Level”.

im sorry i dont understand what your saying

Erase those lines.

i did that but i did not find the void update() and i have 2 error codes saying "the name level does not exist in the current context

Ok, you are almost there, you have a lot of errors, don’t know what went wrong with your code.

In your code you have an int called level, rename it to Level, with a capital letter, this should do the trick.

rename the int or the level?

Like this.

int level; //Instead of this
int Level; //Use this

yep that did the trick no more errors

1 Like

Privacy & Terms