Can't add script.MonoBehaviour problem

Capture
I don’t know how to solve this. Help me please

1 Like

Hi,

This error message is actually incorrect, it is generated when you have a class which has a filename that doesn’t match, this is a requirement within Unity.

Example.cs

public class Example : MonoBehaviour
{
    // ..
}

AnotherExample.cs

public class AnotherExample : MonoBehaviour
{
    // ...
}

Both of the above will be ok, the following won’t be;

Words.cs

public class Word : MonoBehaviour
{
    // ...
} 

In the above, the class name and filename do not match, when Unity compiles - or tries to - the code the error message you’ve taken a screenshot will appear.

Solution - rename your filename to match your class name.

Hope this helps :slight_smile:

Thank you for helping me.I appreciate it and keep up the good work!

1 Like

You’re very welcome :slight_smile:

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

Privacy & Terms