Whenever I try to attach a script to a game object ( whether via dragging or add Component ) It always returns this error saying, "Can't add script component'scipt' because the script class cannot be found. Make sure that there are no compile errors and that the file name and class name match." Anyone know how to solve this problem?
Asked
Active
Viewed 357 times
0
-
BTW, this message is also shown if your script has compilation errors... – One Full Time Equivalent Aug 22 '22 at 06:48
2 Answers
1
- You checked editor console? No error logs? If yes attach console log with errors here
- Check name your script, one of the classes in this script must named by file name
Example:
MyClass.cs
containspublic class MyClass : MonoBehaviour

Alemkhan Utepkaliev
- 230
- 1
- 9
-
1Nope no nothing, I literally created a new script with no errors or anything, and tried to attach it to a GameObject and it said that the script didn't exist – Super not very smart guy Aug 23 '22 at 03:58
-
-
0
1.Your Class should inherit MonoBehaviour, otherwise it can't attach to a GameObject.
2.The file name should be same as the class name
Here's an example:
using UnityEngine;
public MyClass:MonoBehaviour
{
void Start(){}
void Update(){}
}

yingdi fu
- 1
- 1