我对Unity和OOP不太熟悉。我的问题是,在声明类的实例时,即时消息不断出现nullexception错误,尽管我认为我认识到创建新实例的每个步骤。
我尝试使用关键字null,但它再次引发相同的错误。
QuizLogic.cs:
{
public anyobj obj;
void Load(){
if (CurrentQuestion == null){
CurrentQuestion = new anyobj(GameControll.Controll.anyobj)
}
}
void Start(){
Load();
}
}
GameControll.cs:
public class GameControll : MonoBehaviour
{
//
public static GameControll Controll;
public obj anyobj = new obj("anything",false,3,"3");
void Start()
{
if (Controll == null) {
Controll = this;
}
DontDestroyOnLoad(gameObject);
SceneManager.LoadScene("Menu");
}
// Update is called once per frame
void Update()
{
}
}
anyobj.cs
public anyobj(string somevalues);
public anyobj(anyobj);
I expect that anyobj in QuizLogic.cs would instanciate but it doesent. Thanks for any help :)