Getting an incorrect error

Error:

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	Solution 'DataFetcher' ‎(0 projects)	Assets/Control.cs	34	

Code:

DataObject weather = gameObject.AddComponent<DataObject>();

The error’s probably on a different line.

Try putting the ‘weather’ variable outside of any functions, and then set it in start. Example:

DataObject weather;

void Start()
{
weather = gameObject.AddComponent();
}

That should fix it. :slight_smile: