I have created a class called ‘Controller’. From another class, I then declare:
public Controller myController;
But Unity tells me that the ‘type or namespace Controller could not be found’. Is there a special place on the filepath that classes need to go in order to be recognised by Unity?
the only requirement is that controller was either compiled in a previous step or the same. Check out the compile order documentation thats part of the advanced ref
I’ve checked out those docs and tried every combination I can think of. Unity either says it can’t find the type, or it gives this warning:
You are trying to create a MonoBehaviour using the ‘new’ keyword. This is not allowed. MonoBehaviours can only be added using AddComponent(). Alternatively, your script can inherit from ScriptableObject or no base class at all
My controller class doesn’t inherit from anything at the moment. If I make it inherit from ScriptableObject it tells me it can’t find the type ‘ScriptableObject’.
I’m starting to think there’s something wrong with my copy of Unity. All I’m trying to do is create a class and instantiate it.
If your class inherits from MonoBehaviour (by default, they always do) then you can’t create an instance using the new operator. Just to be sure, click on the error bar at the bottom of the window to open the console. Check that you aren’t getting any compile errors with the Controller file that are being “hidden” by the other error.