I got an error when I try to attach my script to a gameObject.
'EnemyBehaviour' is missing the class attribute 'ExtensionOfNativeClass'!
Another times, I got:
Can't add script behaviour CallbackExecutor. The script needs to derive from Monobehaviour!
I have made sure my class derives from MonoBehaviour.
GameObjects are the fundamental objects in Unity that represent characters, props and scenery. They do not accomplish much in themselves but they act as containers for Components, which implement the real functionality. For example, a Light object is created by attaching a Light component to a GameObject.
To create a MonoBehaviour you must use AddComponent on a GameObject. Further than that you cannot create a new GameObject at class scope. It must be done in a method once the game is running, an ideal place to do this would be in Awake.
Classes are the blueprints for your objects. Basically, in Unity, all of your scripts will begin with a class declaration. Unity automatically puts this in the script for you when you create a new C# script. This class shares the name as the script file that it is in.
To solve your issue:
Fix all compiler errors of this script and all other scripts. Compile errors in other scripts can cause the Unity Editor not be able to analyze your current script. Go to your code in visual studio and build the entire solution. Fix all compiler errors before going back to Unity Editor.
Make sure the class inside your script is inherited from MonoBehaviour. This is the obvious one but surprisingly, sometimes, you still get this message even if your class is inherited from MonoBehaviour! If so, you should fix all compiler errors in other scripts (Read item #1).
Make sure the class name is exactly the same as the script name (even the same capitalization).
I solved mine by fixing a compiler error in a different script (item #1) and fixing a typo in my script file name (item #3).
In my case, this error was caused by a reference to an old version of a class that used to derive from MonoBehaviour(in current version, it does not). All that I had to do was to remove it from the GameObject on the scene.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With