Unityについてです。
下記のコードの元、InputFieldの値を変数に代入したいのですが、エラーが起きてしまいます。
どうすればいいですか?回答お願いします。
エラー
NullReferenceException: Object reference not set to an instance of an object
Message+<Startfase>c__Iterator1.MoveNext () (at Assets/Message.cs:80)
UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) (at /Users/builduser/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)
コード
public class Message : MonoBehaviour { public InputField inputField; public Text InputText; public Text messagewindow; public GameObject InputF; int En = 0; string pl; int fase = 0; int flee = 0; int Wait = 0; int m_syori = 0; string daihon; string playername; int Z; private void Start() { StartCoroutine("Startfase"); } // OutputMessage 引数 string IEnumerator OutputMessage(string msg) { flee = 1; m_syori = 1; //string daihon = daihonrist[messagezan]; transform.position = new Vector2(-0.8f, -5.5f); // 引数でもらった文字列の文字数分繰り返し for (int i = 0; i < msg.Length; i++) { var outputText = msg.Substring(i, 1); // 先頭からi文字目を切り出す messagewindow.text = messagewindow.text + outputText;// テキストに反映 yield return new WaitForSeconds(Wait); // x秒待つ } m_syori = 0; Debug.Log("hai"); while (Z == 0) { yield return new WaitForSeconds(0.01f); } messagewindow.text = ""; flee = 0; transform.position = new Vector2(1000, 1000); } IEnumerator Startfase() { inputField = GetComponent<InputField>(); InputText = GetComponent<Text>(); InputF.SetActive(false); daihon = "あなたの名前は?";//daihonrist[messageenzan]; messagewindow.text = "";//textを初期化 StartCoroutine("OutputMessage", daihon); fase = 1; Debug.Log(playername); while (flee == 1) { yield return new WaitForSeconds(0.01f); } m_syori = 0; InputF.SetActive(true); while (En == 0) { yield return new WaitForSeconds(0.01f); } playername = inputField.text;//エラーが起きる部分はここら辺 Debug.Log(playername+":"+inputField.text); yield return new WaitForSeconds(0.01f); InputF.SetActive(false); Debug.Log(playername); daihon = playername;//daihonrist[messageenzan]; messagewindow.text = "";//textを初期化 StartCoroutine("OutputMessage", daihon); fase = 1; while (flee == 1) { yield return new WaitForSeconds(0.01f); } m_syori = 0; } private void Update() { if (Input.GetKeyDown(KeyCode.Return)) { En = 1; } else { En = 0; } if (Input.GetKeyDown(KeyCode.Z)) { Z = 1; } else { Z = 0; } if ((fase == 1) && (Input.GetKeyDown(KeyCode.KeypadEnter))) { playername = inputField.text; Debug.Log(playername); } } ```````````````````````````````````````````````````````````````````@
回答1件
あなたの回答
tips
プレビュー