I'm using new to create multiple monobehaviour class. It works where I can control many game objects with one script but I get this warning saying "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".
Here's my script.
var test1;
test1 = new AnimationMoveNew();
test1.WaitAndMove("Cylinder.423");
Should I worry about the warning, or can I leave it because it builds and run without any problem.
Generally speaking this can cause problems, because certain parts of the Monobehaviour class rely on being connected to a valid GameObjects. If you don't happen to make use of those parts, you may not run into problems, but essentially - because it's not supported - the same rules as using undocumented functions apply: you run the risk that your code may act unpredictably, and the behaviour may change or break in future updates or versions of Unity.
The correct way is to to add your monobehaviour to an existing gameobject, like this:
(Javascript)
var thisInstance = someGameObject.AddComponent(MyScriptName);
or create a new empty gameobject and attach your monobehaviour instance to it, like this:
var newGO = new GameObject("new name");
var thisInstance = newGO.AddComponent(MyScriptName);
You can always destroy the temporary gameobject when you're finished with it, using Destroy()