I have two scripts (for example Script1(for creating data) and Script2(for working with data)) in one object, Main Camera.
Script1:
namespace something
{
public class Data
{
public GameObject obj;
}
[ExecuteInEditMode]
public class Create: MonoBehaviour
{
Data[] data;
void Start()
{
data = new Data[NumData()]; //NumData() = int (e.g. 5)
CallFunction();
}
void CallFunction()
{
foreach(Transform obj in object)
{
for(int id = 0; id < NumData(); id++)
{
data[id].obj = object.gameObject;
}
}
//... etc
Script2:
using something;
[ExecuteInEditMode]
public class WorkWithData: MonoBehaviour
{
Data[] data;
void Update()
{
data = new Data[NumData()];
for (int id = 0; id < NumData(); id++)
{
data[id] = gameObject.GetComponent<Data>();
}
CallFunction();
}
void CallFunction()
{
//just getting information about data[].obj
//...
But Script2 gives an error:
ArgumentException: GetComponent requires that the requested component 'Data' derives from MonoBehaviour or Component or is an interface.
I know it says I must write:
public Class Data : MonoBehaviour
In Script1.
But when I write it, Script1 gives a warning:
You are trying to create a MonoBehaviour using the 'new' keyword. This is not allowed.
When I put script2 into script1, like a new class, it works correctly. But I want it to be separated into more scripts.
I´m a newbie in scripting and programming, so I'm glad for any advice.