プログラミング初心者です。
Unityでゲームを開発しているのですが
NullReferenceException: Object reference not set to an instance of an object
とエラーが出てしまいます。
該当箇所を見てもきちんと値を代入しているのでなぜエラーが出るのかわかりません。
どんなことでもいいので回答お願いします!!!
C#
1using System.Collections.Generic; 2using UnityEngine; 3using UnityEngine.UI; 4public class Question : MonoBehaviour { 5 private Text targetText; 6 private List<string> QuestionList = new List<string>() ; 7 // Use this for initialization 8 void Awake() 9 { 10 QuestionAdd(); 11 } 12 13 void Start() { 14 this.targetText = this.GetComponent<Text>(); 15 16 Questionset(); 17 18 } 19 20 // Update is called once per frame 21 void Update() { 22 if (Input.GetKeyDown(KeyCode.Return)) 23 { 24 Questionset(); 25 } 26 } 27 28 29 public void Questionset() 30 { 31 32 string no = ListExtension.GetAndRemoveAtRandom(QuestionList); 33 targetText.text = no;//ここがエラーと表示されます!!! 34 35 } 36 void QuestionAdd() 37 { 38 QuestionList = new List<string>() { 39 "問題一", 40 "もんだいに", 41 "さん" 42 }; 43 44 } 45 46 47}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。