Person に Quest オブジェクトを追加しようとしています。一方は成功し、もう一方は nullreferenceexception を返します。ここで何が間違っているのでしょうか? PS プレーヤーとリクエスターは、Unity インスペクターで設定されます。
public class GameCreator : MonoBehaviour {
private Quest quest;
public Player player;
public Requestor requestor;
void Start() {
quest = createQuest();
requestor.thisPerson.SetQuest(quest); //this is the problem
player.thisPerson.SetQuest(quest);
}
}
public class Player : MonoBehaviour {
public Person thisPerson;
void Start() {
thisPerson = new Person("Name");
}
}
public class Requestor: MonoBehaviour {
public Person thisPerson;
void Start() {
thisPerson = new Person("Name");
}
}
public class Person {
public Quest quest;
void SetQuest(Quest quest) {
this.quest = quest;
}
}
これがうまくいかない理由はありますか?