質問編集履歴

4

情報更新

2017/01/24 22:30

投稿

okayamamame
okayamamame

スコア9

test CHANGED
File without changes
test CHANGED
@@ -20,17 +20,71 @@
20
20
 
21
21
 
22
22
 
23
- 上記サイトを参考に自分なりに処理を加えたらうまく動きません。
23
+ 上記サイトを参考に自分なりに処理を加えたら
24
24
 
25
- 正誤判別をする箇所上手くいきません。
25
+ **「押されたボタンと回答チェック」「不正解」にしかいきません。**
26
+
27
+
28
+
29
+ 自分なりの処理は
30
+
31
+ ・クイズ問題をCSVから読み込み配列に代入
32
+
33
+ ・配列の代入値をボタンのテキストに利用
34
+
35
+ です。
26
36
 
27
37
 
28
38
 
29
39
  ------------------------------------
30
40
 
31
- 押されたボタンと回答チェック
41
+ CSVから読み込み--Title.cs
32
42
 
43
+ ------------------------------------
44
+
45
+ ```
46
+
47
+ TextAsset mondaiTextFile = Resources.Load("quiz",typeof(TextAsset)) as TextAsset;
48
+
49
+ mondai = mondaiTextFile.text.Split("\n"[0]);
50
+
51
+
52
+
53
+ ・・・
54
+
55
+
56
+
57
+ mondai_mondai[i] = mondai[i].Split(","[0])[0];
58
+
59
+ mondai_kotae[i] = mondai[i].Split(","[0])[1];
60
+
61
+
62
+
63
+ ・・・
64
+
65
+ ```
66
+
67
+ ------------------------------------
68
+
69
+ ボタンへのテキスト挿入--mondai.cs
70
+
71
+ ------------------------------------
72
+
73
+
74
+
75
+ ```
76
+
77
+ Text sButton1=GameObject.Find("CanvasQuizAnsButton1").GetComponentInChildren<Text>();
78
+
79
+ sButton1.text=TitleManager.mondai_sentaku_1[0];
80
+
81
+ ```
82
+
83
+
84
+
85
+ ------------------------------------
86
+
33
- judgde.cs
87
+ 押されたボタンと回答のチェック--judgde.cs
34
88
 
35
89
  ------------------------------------
36
90
 
@@ -104,26 +158,6 @@
104
158
 
105
159
  UnityEngine.Debug:Log(Object)
106
160
 
107
-
108
-
109
- ------------------------------------
110
-
111
- ボタンへのテキスト挿入
112
-
113
- mondai.cs
114
-
115
- ------------------------------------
116
-
117
-
118
-
119
- ```ここに言語を入力
120
-
121
- Text sButton1=GameObject.Find("CanvasQuizAnsButton1").GetComponentInChildren<Text>();
122
-
123
- sButton1.text=TitleManager.mondai_sentaku_1[0];
124
-
125
- ```
126
-
127
161
 
128
162
 
129
163
  試した所、「不正解」にしかいきません。

3

初心者マークをつけた

2017/01/24 22:30

投稿

okayamamame
okayamamame

スコア9

test CHANGED
File without changes
test CHANGED
File without changes

2

タグの追加

2017/01/24 12:56

投稿

okayamamame
okayamamame

スコア9

test CHANGED
File without changes
test CHANGED
File without changes

1

質問内容を具体的にした。

2017/01/24 12:42

投稿

okayamamame
okayamamame

スコア9

test CHANGED
File without changes
test CHANGED
@@ -14,47 +14,123 @@
14
14
 
15
15
 
16
16
 
17
- ボタンに文字を挿入しておいて、クリックした時にボタンのテキストを読み、答えとあっているか判断するものです。
17
+ ボタンにテキスト文字を挿入しておいて、クリックした時にボタンのテキスト文字を読み、答えとあっているか判断するものです。
18
18
 
19
19
 
20
+
21
+
22
+
23
+ 上記サイトを参考に自分なりに処理を加えたらうまく動きません。
20
24
 
21
25
  正誤判別をするの箇所で上手くいきません。
22
26
 
23
27
 
24
28
 
25
- -----------------
29
+ ------------------------------------
26
30
 
27
- /選択したボタンのテキストラベル正解テキストを比較して正誤を判定
31
+ 押されたボタンと回答チェック
28
32
 
29
- public void JudgeAnswer(){
33
+ judgde.cs
30
34
 
31
- //正解のデータをテキストでセットする
35
+ ------------------------------------
32
36
 
33
- string answerText = "7歳";
37
+ ```
34
38
 
35
- //選択したボタンのテキストラベルを取得する
39
+ public void JudgdeAnswer(){
36
40
 
41
+
42
+
43
+ string answerText = TitleManager.mondai_kotae[0];
44
+
37
- Text selectedBtn = this.GetComponentInChildren<Text> ();
45
+ Text selectedBtn = this.GetComponentInChildren<Text>();
38
46
 
39
47
 
40
48
 
41
- if (selectedBtn.text == "7歳") {
49
+ Debug.Log("'" + selectedBtn.text + "'");
42
50
 
43
- Debug.Log("正解");
51
+ Debug.Log(answerText.Length);
44
52
 
45
- } else {
53
+ Debug.Log(selectedBtn.text.Length);
46
54
 
55
+ Debug.Log("答え:"+answerText);
56
+
57
+ Debug.Log("選択:"+selectedBtn.text);
58
+
59
+
60
+
61
+ if(answerText == selectedBtn.text){
62
+
63
+ Debug.Log("正解");
64
+
65
+ }else{
66
+
47
- Debug.Log("不正解");
67
+ Debug.Log("不正解");
68
+
69
+ }
48
70
 
49
71
  }
50
72
 
73
+ ```
74
+
75
+
76
+
51
- --------------------
77
+ ------------------------------------
78
+
79
+ コンソール画面
80
+
81
+ ------------------------------------
82
+
83
+ '白'
84
+
85
+ UnityEngine.Debug:Log(Object)
86
+
87
+ 1
88
+
89
+ UnityEngine.Debug:Log(Object)
90
+
91
+ 2
92
+
93
+ UnityEngine.Debug:Log(Object)
94
+
95
+ 答え:白
96
+
97
+ UnityEngine.Debug:Log(Object)
98
+
99
+ 選択:白
100
+
101
+ UnityEngine.Debug:Log(Object)
102
+
103
+ 不正解
104
+
105
+ UnityEngine.Debug:Log(Object)
106
+
107
+
108
+
109
+ ------------------------------------
110
+
111
+ ボタンへのテキスト挿入
112
+
113
+ mondai.cs
114
+
115
+ ------------------------------------
116
+
117
+
118
+
119
+ ```ここに言語を入力
120
+
121
+ Text sButton1=GameObject.Find("CanvasQuizAnsButton1").GetComponentInChildren<Text>();
122
+
123
+ sButton1.text=TitleManager.mondai_sentaku_1[0];
124
+
125
+ ```
52
126
 
53
127
 
54
128
 
55
129
  試した所、「不正解」にしかいきません。
56
130
 
131
+
132
+
57
- selectedBtn.textの文字数を調べてみると文字になっています。
133
+ selectedBtn.textの文字数を調べてみると文字になっています。
58
134
 
59
135
 
60
136