using
1using System.Collections.Generic; 2using UnityEngine; 3using UnityEngine.UI; 4 5public class GameControlloer : MonoBehaviour 6{ 7 InputField inputField; 8 Text text; 9 10 // Start is called before the first frame update 11 public void InputText() 12 { 13 14 text.text = inputField.text; 15 } 16 void Start() 17 { 18 inputField = GameObject.Find("InputField").GetComponent<InputField>(); 19 text = GameObject.Find("Message").GetComponent<Text>(); 20 string x = inputField.text; 21 int monndaisuu = 0; 22 int one = UnityEngine.Random.Range(1, 11); 23 int two = UnityEngine.Random.Range(1, 11); 24 int answer = one + two; 25 Debug.Log(one + "+" + two + "+" + "=" + answer); 26 if(monndaisuu==10) 27 { 28 Debug.Log("成功!"); 29 30 } 31 else if (x == (one + "+" + two + "=" + answer)) 32 { 33 monndaisuu++; 34 GET get= GetComponent<GET>(); 35 } 36 } 37 38 // Update is called once per frame 39 40 41 42 43 44 45 46 47}``` 48と、 49 50 51 52 53```using System.Collections; 54using System.Collections.Generic; 55using UnityEngine; 56 57public class GET : MonoBehaviour 58{ 59 // Start is called before the first frame update 60 void Start() 61 { 62 GetComponent<GameControlloer>(); 63 GameControlloer component = this.gameObject.GetComponent<GameControlloer>(); 64 Destroy(component,0.1f); 65 GetComponent<GameControlloer>(); 66 Destroy(this.gameObject); 67 } 68 69 private GameControlloer gameController; 70 void Update() 71 { 72 73 74 } 75}``` 76関係しているスクリプト二つを貼り付けました 77乱数で計算した答えと同じ数を入力するとコンポーネントをつけなおすというようになっています 78なぜかエラーが出てきました、どうすればよいでしょうか?エラーが出ているところは text = GameObject.Find("Message").GetComponent<Text>();の一列です 79エラー文はこれです 80NullReferenceException: Object reference not set to an instance of an object 81GameControlloer.Start () (at Assets/input/GameControlloer.cs:20)
回答1件
あなたの回答
tips
プレビュー