unity初心者です。
環境はmacでunityを利用しています。
ともに最新安定版を利用しています。
https://engineer.blog.lancers.jp/2015/05/ugui_quiz_unity/
を参考にUnityを勉強中です。
ボタンにテキスト文字を挿入しておいて、クリックした時にボタンのテキスト文字を読み、答えとあっているか判断するものです。
上記サイトを参考に自分なりに処理を加えたら
「押されたボタンと回答のチェック」で「不正解」にしかいきません。
自分なりの処理は
・クイズ問題をCSVから読み込み配列に代入
・配列の代入値をボタンのテキストに利用
です。
CSVからの読み込み--Title.cs
TextAsset mondaiTextFile = Resources.Load("quiz",typeof(TextAsset)) as TextAsset; mondai = mondaiTextFile.text.Split("\n"[0]); ・・・ mondai_mondai[i] = mondai[i].Split(","[0])[0]; mondai_kotae[i] = mondai[i].Split(","[0])[1]; ・・・
ボタンへのテキスト挿入--mondai.cs
Text sButton1=GameObject.Find("CanvasQuizAnsButton1").GetComponentInChildren<Text>(); sButton1.text=TitleManager.mondai_sentaku_1[0];
押されたボタンと回答のチェック--judgde.cs
public void JudgdeAnswer(){ string answerText = TitleManager.mondai_kotae[0]; Text selectedBtn = this.GetComponentInChildren<Text>(); Debug.Log("'" + selectedBtn.text + "'"); Debug.Log(answerText.Length); Debug.Log(selectedBtn.text.Length); Debug.Log("答え:"+answerText); Debug.Log("選択:"+selectedBtn.text); if(answerText == selectedBtn.text){ Debug.Log("正解"); }else{ Debug.Log("不正解"); } }
コンソール画面
'白'
UnityEngine.Debug:Log(Object)
1
UnityEngine.Debug:Log(Object)
2
UnityEngine.Debug:Log(Object)
答え:白
UnityEngine.Debug:Log(Object)
選択:白
UnityEngine.Debug:Log(Object)
不正解
UnityEngine.Debug:Log(Object)
試した所、「不正解」にしかいきません。
selectedBtn.textの文字数を調べてみると2文字になっています。
this.GetComponentInChildren<Text> ()でボタンの文字を取得したときには文字データ以外に何か付属でデータ、改行コードなどが入るのでしょか?
また、文字型の変数に入っている改行コードなどを可視化する方法があったら教えて下さい。
回答1件
あなたの回答
tips
プレビュー