質問するログイン新規登録

質問編集履歴

3

コードの編集

2021/11/29 01:57

投稿

taaiii
taaiii

スコア6

title CHANGED
File without changes
body CHANGED
@@ -231,6 +231,39 @@
231
231
  void Update() { }
232
232
  }
233
233
  ```
234
+ ```C#
235
+ using System.Collections;
236
+ using System.Collections.Generic;
237
+ using UnityEngine;
238
+ using UnityEngine.UI;
239
+ using System.IO;
240
+ using System.Linq;
241
+
242
+ public class Game1 : MonoBehaviour
243
+ {
244
+
245
+ public static int qCount;
246
+
247
+ public void NextQuiz()
248
+ {
249
+ if (Application.loadedLevelName == "Result1")
250
+ {
251
+ if (qCount < 5)
252
+ {
253
+ qCount++;
254
+ Application.LoadLevel("1F");
255
+ }
256
+ else
257
+ {
258
+ qCount = 0;
259
+ Application.LoadLevel("Score1");
260
+ }
261
+ }
262
+ }
263
+
264
+
265
+ }
266
+ ```
234
267
  ### 補足情報
235
268
 
236
269
  unityは2021.2.2f1です。

2

コードの編集

2021/11/29 01:57

投稿

taaiii
taaiii

スコア6

title CHANGED
File without changes
body CHANGED
@@ -80,37 +80,7 @@
80
80
  }
81
81
  }
82
82
  ```
83
- ```C#
84
- using System.Collections;
85
- using System.Collections.Generic;
86
- using UnityEngine;
87
- using UnityEngine.UI;
88
- using System.IO;
89
- using System.Linq;
90
83
 
91
- public class GameStart : MonoBehaviour
92
- {
93
- public static int qCount;
94
-
95
- public void NextQuiz()
96
- {
97
-      if (Application.loadedLevelName == "Result")
98
- {
99
-
100
- if (qCount < 4)
101
- {
102
- qCount++;
103
- Application.LoadLevel("1F");
104
- }
105
- else
106
- {
107
- qCount = 0;
108
- Application.LoadLevel("Score");
109
- }
110
- }
111
- }
112
- }
113
- ```
114
84
  ```C#
115
85
  using System.Collections;
116
86
  using System.Collections.Generic;

1

該当のコードの追加

2021/11/29 01:51

投稿

taaiii
taaiii

スコア6

title CHANGED
File without changes
body CHANGED
@@ -131,6 +131,136 @@
131
131
  }
132
132
  }
133
133
  ```
134
+ ```C#
135
+ using System.Collections;
136
+ using System.Collections.Generic;
137
+ using UnityEngine;
138
+ using UnityEngine.UI;
139
+ using System.IO;
140
+
141
+ public class Judge1 : MonoBehaviour
142
+ {
143
+
144
+ QuizMgr quizMgr;
145
+ string answerText;
146
+
147
+ void Start()
148
+ {
149
+ quizMgr = GameObject.Find("Main Camera").GetComponent<QuizMgr>();
150
+ answerText = quizMgr.AnswerText;
151
+ }
152
+
153
+ //選択したボタンのテキストラベルと正解のテキストを比較して正誤を判定
154
+ public void Answer()
155
+ {
156
+ //選択したボタンのテキストを取得する
157
+ Text selectedBtn = this.GetComponentInChildren<Text>();
158
+ Debug.Log("セレクト'" + selectedBtn.text + "'");
159
+ Debug.Log("アンサー'" + answerText + "'");
160
+
161
+ if (answerText == selectedBtn.text){
162
+ ResultMgr.SetJudgeData("正解");
163
+ Debug.Log("正解");
164
+ Application.LoadLevel("Result1");
165
+ } else {
166
+ ResultMgr.SetJudgeData("不正解");
167
+ Debug.Log("不正解");
168
+ Application.LoadLevel("Result1");
169
+ }
170
+ }
171
+ }
172
+ ```
173
+ ```C#
174
+ using System.Collections;
175
+ using System.Collections.Generic;
176
+ using UnityEngine;
177
+ using UnityEngine.UI;
178
+ using System.IO;
179
+ using System.Linq;
180
+
181
+ public class QuizMgr : MonoBehaviour
182
+ {
183
+ public string dataName;
184
+ public string title;
185
+ public TextAsset csvFile;
186
+ public List<string[]> csvDatas = new List<string[]>();
187
+ public int height = 0;
188
+ public int i, j = 0;
189
+ public int k = 0;
190
+ internal Text ansLabel;
191
+ public string AnswerText;
192
+ public string Kaisetsubun;
193
+ const int size = 5;
194
+
195
+
196
+ void Start()
197
+ {
198
+ title = "theme_";
199
+ csvFile = Resources.Load("CSV/" + title + dataName) as TextAsset;
200
+ StringReader reader = new StringReader(csvFile.text);
201
+
202
+ while (reader.Peek() > -1)
203
+ {
204
+ string line = reader.ReadLine();
205
+ csvDatas.Add(line.Split(','));
206
+ Debug.Log("reading:" + height);
207
+ height++;
208
+ }
209
+
210
+ for (i = 0; i < height; i++)
211
+ {
212
+ for (j = 0; j < size; j++)
213
+ {
214
+ Debug.Log("csvDatas[" + i + "][" + j + "]:" + csvDatas[i][j]);
215
+ }
216
+ }
217
+
218
+ QuestionLabelSet();
219
+ AnswerLabelSet();
220
+ AnswerSet();
221
+ }
222
+
223
+
224
+ public void QuestionLabelSet()
225
+ {
226
+ csvDatas[k] = csvDatas[Random.Range(0, 9)];
227
+
228
+ //特定の名前のオブジェクトを検索してアクセス
229
+ Text qLabel = GameObject.Find("Quiz/Image/QLabel").GetComponentInChildren<Text>();
230
+ //データをセットすることで、既存情報を上書きできる
231
+ qLabel.text = csvDatas[k][0];
232
+ }
233
+
234
+ public void AnswerLabelSet()
235
+ {
236
+ //問題文に対応した答えをそれぞれのuGUIボタンにセット
237
+ string[] array = new string[] { csvDatas[k][1], csvDatas[k][2], csvDatas[k][3], csvDatas[k][4] };
238
+
239
+ //問題文をシャッフル
240
+ array = array.OrderBy(x => System.Guid.NewGuid()).ToArray();
241
+
242
+
243
+ //ボタンが4つあるのでそれぞれ代入
244
+ for (int i = 1; i <= 4; i++)
245
+ {
246
+ Text ansLabel = GameObject.Find("Quiz/AnsButton" + i).GetComponentInChildren<Text>();
247
+ ansLabel.text = array[i - 1];
248
+ }
249
+ }
250
+
251
+ public void AnswerSet()
252
+ {
253
+ //答えとなるcsvデータを変数として型に代入する
254
+ AnswerText = csvDatas[k][1];
255
+ Debug.Log ("アンサーセット'" + AnswerText + "'");
256
+
257
+ Kaisetsubun = csvDatas[k][5];
258
+ Debug.Log(Kaisetsubun);
259
+ }
260
+
261
+ void Update() { }
262
+ }
263
+ ```
134
264
  ### 補足情報
135
265
 
136
266
  unityは2021.2.2f1です。