###前提・実現したいこと
打ち込まれた文字列から特定の文字列の湯有無を判定し、適当な言葉を返す人工無能の試作品(製作中)
###発生している問題・エラーメッセージ
IndexOutOfRangeException: Array index is out of range. SaveScript.SaveText () (at Assets/script/SaveScript.cs:36) NullReferenceException: Object reference not set to an instance of an object SaveScript.Start () (at Assets/script/SaveScript.cs:24) UnassignedReferenceException: The variable unity of SaveScript has not been assigned. You probably need to assign the unity variable of the SaveScript script in the inspector.
###該当のソースコード
using UnityEngine; using UnityEngine.UI; using System.Collections; public class SaveScript : MonoBehaviour { string str; string que; string before; string after; string namae; public InputField inputField; public Text text; public Text talk; public Text feel; public InputField your; int i; int a; public GameObject unity; int feeling = 2; void Start () { talk.text = "はじめまして私unity、私とおしゃべりしませんか?"; unity.GetComponent<Animator> ().SetBool ("talk", true); } public void SaveText () { str = inputField.text; text.text = str; before = str; namae = your.text; //普通なら辞書にあたる部分 string[] gimon = { "私", "わたし", "わたくし", "俺", "おれ", "自分", "じぶん", "僕", "ぼく" }; for (a = 0; a <= 9; a++) { que = before.Replace (gimon [a], "なぜあなた"); } string[] stArrayData = {"おはよう", "こんにちは", "こんばんは", "めまして", "趣味", "ゲーム", "私", "わたし", "わたくし", "俺", "おれ", "自分", "じぶん", "僕", "ぼく", "人工", "ばか", "莫迦", "馬鹿", "好き", "思う", "そんなことない", "", }; string[] sadhennji = {"・・・", "・・・", "・・・", "あ?", "・・・", "・・・", "・・・", "・・・", "・・・", "・・・" , "",}; string[] hennji = {"おはよう!", "こんにちは!", "こんばんは!", "始めまして!", "あなたの趣味はなんですか?", "私、ゲーム大好きです", que + "か?", que + "か?", que + "か?", que + "か?", que + "か?", que + "か?", que + "か?", que + "か?", que + "か?", "私は人工知能なのでなんとも・・・", "馬鹿って私のことですか!", "馬鹿って私のことですか!" , "馬鹿って私のことですか!", "私も好きです!", "私賢くないのでなのでなんとも・・・", "そうですか?"}; string[] happyhennji = {"おはよう" + namae, "こんにちは" + namae + "!", "こんばんは" + namae + "!" , "始めまして" + namae + "!", "", "", "", "", "", "" , "",}; //ここから普通正規表現等を使う部分 for (i = 0; i <= 100; i++) { switch (feeling) { case 1: after = before.Replace (stArrayData [i], ""); if (!(before == after)) { talk.text = sadhennji [i]; i = 100; } else { if (i <= 100) { talk.text = "よくわかりません"; } }break; case 2: after = before.Replace (stArrayData [i], ""); if (!(before == after)) { talk.text = hennji [i]; i = 100; } else { if (i <= 100) { talk.text = "へぇ~"; } }break; case 3: after = before.Replace (stArrayData [i], ""); if (!(before == after)) { talk.text = happyhennji [i]; unity.GetComponent<Animator> ().SetBool ("talk", false); i = 100; } else { if (i <= 100) { talk.text = "ごめんなさいよくわかりませんでした"; } }break; } } unity.GetComponent<Animator> ().SetBool ("talk", true); } }//savescript
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/07/19 11:12