Синтаксис:
Используется csharp
public class Script_1 : MonoBehaviour {
public int a = 1;
}
public int a = 1;
}
Синтаксис:
Используется csharp
public class Script_2 : MonoBehaviour {
void Start(){
Script_1 s1 = new Script_1();
s1.a = 4;
}
}
void Start(){
Script_1 s1 = new Script_1();
s1.a = 4;
}
}
Всё работает, переменная меняется, но выдаётся такое:
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
UnityEngine.MonoBehaviour:.ctor()
Script_1:.ctor()
Script_2:Start() (at Assets/Scripts/Script_2.cs:7)
В чём дело?