-1

My script is called Grid and when i try and drag it into a game object it says "cant add script as script class can't be found. Make sure that there are no compile errors and that the file name and class name match." what should i do, because the problem isn't the name i know thats different its to do with the arrows because they invalid data types when naming.

My script

  • Does this answer your question? [Can't add script component because the script class cannot be found?](https://stackoverflow.com/questions/51713497/cant-add-script-component-because-the-script-class-cannot-be-found) – joll05 Apr 03 '22 at 13:34
  • Please show us your script .. – derHugo Apr 03 '22 at 13:36
  • 1
    A) your class is not a `MonoBehaviour` .. B) you can only Instantiate and use as component a non-generic class .. otherwise how should unity know what to pass in as generic type parameter? ;) You will need an actual implementation of your class ... – derHugo Apr 03 '22 at 14:05

1 Answers1

1

In Unity for a Script/Class to be added to a GameObject, your class needs to inherit MonoBehaviour. Like this:

public class Grid<TGridObjects>:MonoBehaviour

If you just want to execute functions in your Script without making it MonoBehaviour, you can call from another MonoBehaviour

Grid<sth> myVar = new Grid<sth>();

Also Note that the Filename "Grid.cs" needs to correspond to your classname Grid if you are using MonoBehaviours.

cpaech
  • 86
  • 4