0

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?

2 Answers2

1
  1. You checked editor console? No error logs? If yes attach console log with errors here
  2. Check name your script, one of the classes in this script must named by file name Example: MyClass.cs contains public class MyClass : MonoBehaviour
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