質問編集履歴

3

コードの編集

2021/11/29 01:57

投稿

taaiii
taaiii

score6

test CHANGED
File without changes
test CHANGED
@@ -464,6 +464,72 @@
464
464
 
465
465
  ```
466
466
 
467
+ ```C#
468
+
469
+ using System.Collections;
470
+
471
+ using System.Collections.Generic;
472
+
473
+ using UnityEngine;
474
+
475
+ using UnityEngine.UI;
476
+
477
+ using System.IO;
478
+
479
+ using System.Linq;
480
+
481
+
482
+
483
+ public class Game1 : MonoBehaviour
484
+
485
+ {
486
+
487
+
488
+
489
+ public static int qCount;
490
+
491
+
492
+
493
+ public void NextQuiz()
494
+
495
+ {
496
+
497
+ if (Application.loadedLevelName == "Result1")
498
+
499
+ {
500
+
501
+ if (qCount < 5)
502
+
503
+ {
504
+
505
+ qCount++;
506
+
507
+ Application.LoadLevel("1F");
508
+
509
+ }
510
+
511
+ else
512
+
513
+ {
514
+
515
+ qCount = 0;
516
+
517
+ Application.LoadLevel("Score1");
518
+
519
+ }
520
+
521
+ }
522
+
523
+ }
524
+
525
+
526
+
527
+
528
+
529
+ }
530
+
531
+ ```
532
+
467
533
  ### 補足情報
468
534
 
469
535
 

2

コードの編集

2021/11/29 01:57

投稿

taaiii
taaiii

score6

test CHANGED
File without changes
test CHANGED
@@ -162,6 +162,8 @@
162
162
 
163
163
  ```
164
164
 
165
+
166
+
165
167
  ```C#
166
168
 
167
169
  using System.Collections;
@@ -172,358 +174,296 @@
172
174
 
173
175
  using UnityEngine.UI;
174
176
 
177
+
178
+
179
+ public class Score : MonoBehaviour
180
+
181
+ {
182
+
183
+ // Use this for initialization
184
+
185
+ void Start()
186
+
187
+ {
188
+
189
+ //スコア表示用のゲームオブジェクトを取得
190
+
191
+ Text scoreLabel = GameObject.Find("Canvas/Score").GetComponent<Text>();
192
+
193
+ scoreLabel.color = Color.red;
194
+
195
+ //グローバルに宣言したスコアをResultMgrのスクリプトから読み込む
196
+
197
+ int Score = ResultMgr.GetScoreData();
198
+
199
+ scoreLabel.text = Score.ToString() + " 問正解";
200
+
201
+ }
202
+
203
+ }
204
+
205
+ ```
206
+
207
+ ```C#
208
+
209
+ using System.Collections;
210
+
211
+ using System.Collections.Generic;
212
+
213
+ using UnityEngine;
214
+
215
+ using UnityEngine.UI;
216
+
175
217
  using System.IO;
176
218
 
219
+
220
+
221
+ public class Judge1 : MonoBehaviour
222
+
223
+ {
224
+
225
+
226
+
227
+ QuizMgr quizMgr;
228
+
229
+ string answerText;
230
+
231
+
232
+
233
+ void Start()
234
+
235
+ {
236
+
237
+ quizMgr = GameObject.Find("Main Camera").GetComponent<QuizMgr>();
238
+
239
+ answerText = quizMgr.AnswerText;
240
+
241
+ }
242
+
243
+
244
+
245
+ //選択したボタンのテキストラベルと正解のテキストを比較して正誤を判定
246
+
247
+ public void Answer()
248
+
249
+ {
250
+
251
+ //選択したボタンのテキストを取得する
252
+
253
+ Text selectedBtn = this.GetComponentInChildren<Text>();
254
+
255
+ Debug.Log("セレクト'" + selectedBtn.text + "'");
256
+
257
+ Debug.Log("アンサー'" + answerText + "'");
258
+
259
+
260
+
261
+ if (answerText == selectedBtn.text){
262
+
263
+ ResultMgr.SetJudgeData("正解");
264
+
265
+ Debug.Log("正解");
266
+
267
+ Application.LoadLevel("Result1");
268
+
269
+ } else {
270
+
271
+ ResultMgr.SetJudgeData("不正解");
272
+
273
+ Debug.Log("不正解");
274
+
275
+ Application.LoadLevel("Result1");
276
+
277
+ }
278
+
279
+ }
280
+
281
+ }
282
+
283
+ ```
284
+
285
+ ```C#
286
+
287
+ using System.Collections;
288
+
289
+ using System.Collections.Generic;
290
+
291
+ using UnityEngine;
292
+
293
+ using UnityEngine.UI;
294
+
295
+ using System.IO;
296
+
177
297
  using System.Linq;
178
298
 
179
299
 
180
300
 
181
- public class GameStart : MonoBehaviour
301
+ public class QuizMgr : MonoBehaviour
182
302
 
183
303
  {
184
304
 
185
- public static int qCount;
186
-
187
-
188
-
189
- public void NextQuiz()
190
-
191
- {
192
-
193
-      if (Application.loadedLevelName == "Result")
194
-
195
- {
196
-
197
-
198
-
199
- if (qCount < 4)
200
-
201
- {
202
-
203
- qCount++;
204
-
205
- Application.LoadLevel("1F");
206
-
207
- }
208
-
209
- else
210
-
211
- {
212
-
213
- qCount = 0;
214
-
215
- Application.LoadLevel("Score");
216
-
217
- }
218
-
219
- }
220
-
221
- }
305
+ public string dataName;
306
+
307
+ public string title;
308
+
309
+ public TextAsset csvFile;
310
+
311
+ public List<string[]> csvDatas = new List<string[]>();
312
+
313
+ public int height = 0;
314
+
315
+ public int i, j = 0;
316
+
317
+ public int k = 0;
318
+
319
+ internal Text ansLabel;
320
+
321
+ public string AnswerText;
322
+
323
+ public string Kaisetsubun;
324
+
325
+ const int size = 5;
326
+
327
+
328
+
329
+
330
+
331
+ void Start()
332
+
333
+ {
334
+
335
+ title = "theme_";
336
+
337
+ csvFile = Resources.Load("CSV/" + title + dataName) as TextAsset;
338
+
339
+ StringReader reader = new StringReader(csvFile.text);
340
+
341
+
342
+
343
+ while (reader.Peek() > -1)
344
+
345
+ {
346
+
347
+ string line = reader.ReadLine();
348
+
349
+ csvDatas.Add(line.Split(','));
350
+
351
+ Debug.Log("reading:" + height);
352
+
353
+ height++;
354
+
355
+ }
356
+
357
+
358
+
359
+ for (i = 0; i < height; i++)
360
+
361
+ {
362
+
363
+ for (j = 0; j < size; j++)
364
+
365
+ {
366
+
367
+ Debug.Log("csvDatas[" + i + "][" + j + "]:" + csvDatas[i][j]);
368
+
369
+ }
370
+
371
+ }
372
+
373
+
374
+
375
+ QuestionLabelSet();
376
+
377
+ AnswerLabelSet();
378
+
379
+ AnswerSet();
380
+
381
+ }
382
+
383
+
384
+
385
+
386
+
387
+ public void QuestionLabelSet()
388
+
389
+ {
390
+
391
+ csvDatas[k] = csvDatas[Random.Range(0, 9)];
392
+
393
+
394
+
395
+ //特定の名前のオブジェクトを検索してアクセス
396
+
397
+ Text qLabel = GameObject.Find("Quiz/Image/QLabel").GetComponentInChildren<Text>();
398
+
399
+ //データをセットすることで、既存情報を上書きできる
400
+
401
+ qLabel.text = csvDatas[k][0];
402
+
403
+ }
404
+
405
+
406
+
407
+ public void AnswerLabelSet()
408
+
409
+ {
410
+
411
+ //問題文に対応した答えをそれぞれのuGUIボタンにセット
412
+
413
+ string[] array = new string[] { csvDatas[k][1], csvDatas[k][2], csvDatas[k][3], csvDatas[k][4] };
414
+
415
+
416
+
417
+ //問題文をシャッフル
418
+
419
+ array = array.OrderBy(x => System.Guid.NewGuid()).ToArray();
420
+
421
+
422
+
423
+
424
+
425
+ //ボタンが4つあるのでそれぞれ代入
426
+
427
+ for (int i = 1; i <= 4; i++)
428
+
429
+ {
430
+
431
+ Text ansLabel = GameObject.Find("Quiz/AnsButton" + i).GetComponentInChildren<Text>();
432
+
433
+ ansLabel.text = array[i - 1];
434
+
435
+ }
436
+
437
+ }
438
+
439
+
440
+
441
+ public void AnswerSet()
442
+
443
+ {
444
+
445
+ //答えとなるcsvデータを変数として型に代入する
446
+
447
+ AnswerText = csvDatas[k][1];
448
+
449
+ Debug.Log ("アンサーセット'" + AnswerText + "'");
450
+
451
+
452
+
453
+ Kaisetsubun = csvDatas[k][5];
454
+
455
+ Debug.Log(Kaisetsubun);
456
+
457
+ }
458
+
459
+
460
+
461
+ void Update() { }
222
462
 
223
463
  }
224
464
 
225
465
  ```
226
466
 
227
- ```C#
228
-
229
- using System.Collections;
230
-
231
- using System.Collections.Generic;
232
-
233
- using UnityEngine;
234
-
235
- using UnityEngine.UI;
236
-
237
-
238
-
239
- public class Score : MonoBehaviour
240
-
241
- {
242
-
243
- // Use this for initialization
244
-
245
- void Start()
246
-
247
- {
248
-
249
- //スコア表示用のゲームオブジェクトを取得
250
-
251
- Text scoreLabel = GameObject.Find("Canvas/Score").GetComponent<Text>();
252
-
253
- scoreLabel.color = Color.red;
254
-
255
- //グローバルに宣言したスコアをResultMgrのスクリプトから読み込む
256
-
257
- int Score = ResultMgr.GetScoreData();
258
-
259
- scoreLabel.text = Score.ToString() + " 問正解";
260
-
261
- }
262
-
263
- }
264
-
265
- ```
266
-
267
- ```C#
268
-
269
- using System.Collections;
270
-
271
- using System.Collections.Generic;
272
-
273
- using UnityEngine;
274
-
275
- using UnityEngine.UI;
276
-
277
- using System.IO;
278
-
279
-
280
-
281
- public class Judge1 : MonoBehaviour
282
-
283
- {
284
-
285
-
286
-
287
- QuizMgr quizMgr;
288
-
289
- string answerText;
290
-
291
-
292
-
293
- void Start()
294
-
295
- {
296
-
297
- quizMgr = GameObject.Find("Main Camera").GetComponent<QuizMgr>();
298
-
299
- answerText = quizMgr.AnswerText;
300
-
301
- }
302
-
303
-
304
-
305
- //選択したボタンのテキストラベルと正解のテキストを比較して正誤を判定
306
-
307
- public void Answer()
308
-
309
- {
310
-
311
- //選択したボタンのテキストを取得する
312
-
313
- Text selectedBtn = this.GetComponentInChildren<Text>();
314
-
315
- Debug.Log("セレクト'" + selectedBtn.text + "'");
316
-
317
- Debug.Log("アンサー'" + answerText + "'");
318
-
319
-
320
-
321
- if (answerText == selectedBtn.text){
322
-
323
- ResultMgr.SetJudgeData("正解");
324
-
325
- Debug.Log("正解");
326
-
327
- Application.LoadLevel("Result1");
328
-
329
- } else {
330
-
331
- ResultMgr.SetJudgeData("不正解");
332
-
333
- Debug.Log("不正解");
334
-
335
- Application.LoadLevel("Result1");
336
-
337
- }
338
-
339
- }
340
-
341
- }
342
-
343
- ```
344
-
345
- ```C#
346
-
347
- using System.Collections;
348
-
349
- using System.Collections.Generic;
350
-
351
- using UnityEngine;
352
-
353
- using UnityEngine.UI;
354
-
355
- using System.IO;
356
-
357
- using System.Linq;
358
-
359
-
360
-
361
- public class QuizMgr : MonoBehaviour
362
-
363
- {
364
-
365
- public string dataName;
366
-
367
- public string title;
368
-
369
- public TextAsset csvFile;
370
-
371
- public List<string[]> csvDatas = new List<string[]>();
372
-
373
- public int height = 0;
374
-
375
- public int i, j = 0;
376
-
377
- public int k = 0;
378
-
379
- internal Text ansLabel;
380
-
381
- public string AnswerText;
382
-
383
- public string Kaisetsubun;
384
-
385
- const int size = 5;
386
-
387
-
388
-
389
-
390
-
391
- void Start()
392
-
393
- {
394
-
395
- title = "theme_";
396
-
397
- csvFile = Resources.Load("CSV/" + title + dataName) as TextAsset;
398
-
399
- StringReader reader = new StringReader(csvFile.text);
400
-
401
-
402
-
403
- while (reader.Peek() > -1)
404
-
405
- {
406
-
407
- string line = reader.ReadLine();
408
-
409
- csvDatas.Add(line.Split(','));
410
-
411
- Debug.Log("reading:" + height);
412
-
413
- height++;
414
-
415
- }
416
-
417
-
418
-
419
- for (i = 0; i < height; i++)
420
-
421
- {
422
-
423
- for (j = 0; j < size; j++)
424
-
425
- {
426
-
427
- Debug.Log("csvDatas[" + i + "][" + j + "]:" + csvDatas[i][j]);
428
-
429
- }
430
-
431
- }
432
-
433
-
434
-
435
- QuestionLabelSet();
436
-
437
- AnswerLabelSet();
438
-
439
- AnswerSet();
440
-
441
- }
442
-
443
-
444
-
445
-
446
-
447
- public void QuestionLabelSet()
448
-
449
- {
450
-
451
- csvDatas[k] = csvDatas[Random.Range(0, 9)];
452
-
453
-
454
-
455
- //特定の名前のオブジェクトを検索してアクセス
456
-
457
- Text qLabel = GameObject.Find("Quiz/Image/QLabel").GetComponentInChildren<Text>();
458
-
459
- //データをセットすることで、既存情報を上書きできる
460
-
461
- qLabel.text = csvDatas[k][0];
462
-
463
- }
464
-
465
-
466
-
467
- public void AnswerLabelSet()
468
-
469
- {
470
-
471
- //問題文に対応した答えをそれぞれのuGUIボタンにセット
472
-
473
- string[] array = new string[] { csvDatas[k][1], csvDatas[k][2], csvDatas[k][3], csvDatas[k][4] };
474
-
475
-
476
-
477
- //問題文をシャッフル
478
-
479
- array = array.OrderBy(x => System.Guid.NewGuid()).ToArray();
480
-
481
-
482
-
483
-
484
-
485
- //ボタンが4つあるのでそれぞれ代入
486
-
487
- for (int i = 1; i <= 4; i++)
488
-
489
- {
490
-
491
- Text ansLabel = GameObject.Find("Quiz/AnsButton" + i).GetComponentInChildren<Text>();
492
-
493
- ansLabel.text = array[i - 1];
494
-
495
- }
496
-
497
- }
498
-
499
-
500
-
501
- public void AnswerSet()
502
-
503
- {
504
-
505
- //答えとなるcsvデータを変数として型に代入する
506
-
507
- AnswerText = csvDatas[k][1];
508
-
509
- Debug.Log ("アンサーセット'" + AnswerText + "'");
510
-
511
-
512
-
513
- Kaisetsubun = csvDatas[k][5];
514
-
515
- Debug.Log(Kaisetsubun);
516
-
517
- }
518
-
519
-
520
-
521
- void Update() { }
522
-
523
- }
524
-
525
- ```
526
-
527
467
  ### 補足情報
528
468
 
529
469
 

1

該当のコードの追加

2021/11/29 01:51

投稿

taaiii
taaiii

score6

test CHANGED
File without changes
test CHANGED
@@ -264,6 +264,266 @@
264
264
 
265
265
  ```
266
266
 
267
+ ```C#
268
+
269
+ using System.Collections;
270
+
271
+ using System.Collections.Generic;
272
+
273
+ using UnityEngine;
274
+
275
+ using UnityEngine.UI;
276
+
277
+ using System.IO;
278
+
279
+
280
+
281
+ public class Judge1 : MonoBehaviour
282
+
283
+ {
284
+
285
+
286
+
287
+ QuizMgr quizMgr;
288
+
289
+ string answerText;
290
+
291
+
292
+
293
+ void Start()
294
+
295
+ {
296
+
297
+ quizMgr = GameObject.Find("Main Camera").GetComponent<QuizMgr>();
298
+
299
+ answerText = quizMgr.AnswerText;
300
+
301
+ }
302
+
303
+
304
+
305
+ //選択したボタンのテキストラベルと正解のテキストを比較して正誤を判定
306
+
307
+ public void Answer()
308
+
309
+ {
310
+
311
+ //選択したボタンのテキストを取得する
312
+
313
+ Text selectedBtn = this.GetComponentInChildren<Text>();
314
+
315
+ Debug.Log("セレクト'" + selectedBtn.text + "'");
316
+
317
+ Debug.Log("アンサー'" + answerText + "'");
318
+
319
+
320
+
321
+ if (answerText == selectedBtn.text){
322
+
323
+ ResultMgr.SetJudgeData("正解");
324
+
325
+ Debug.Log("正解");
326
+
327
+ Application.LoadLevel("Result1");
328
+
329
+ } else {
330
+
331
+ ResultMgr.SetJudgeData("不正解");
332
+
333
+ Debug.Log("不正解");
334
+
335
+ Application.LoadLevel("Result1");
336
+
337
+ }
338
+
339
+ }
340
+
341
+ }
342
+
343
+ ```
344
+
345
+ ```C#
346
+
347
+ using System.Collections;
348
+
349
+ using System.Collections.Generic;
350
+
351
+ using UnityEngine;
352
+
353
+ using UnityEngine.UI;
354
+
355
+ using System.IO;
356
+
357
+ using System.Linq;
358
+
359
+
360
+
361
+ public class QuizMgr : MonoBehaviour
362
+
363
+ {
364
+
365
+ public string dataName;
366
+
367
+ public string title;
368
+
369
+ public TextAsset csvFile;
370
+
371
+ public List<string[]> csvDatas = new List<string[]>();
372
+
373
+ public int height = 0;
374
+
375
+ public int i, j = 0;
376
+
377
+ public int k = 0;
378
+
379
+ internal Text ansLabel;
380
+
381
+ public string AnswerText;
382
+
383
+ public string Kaisetsubun;
384
+
385
+ const int size = 5;
386
+
387
+
388
+
389
+
390
+
391
+ void Start()
392
+
393
+ {
394
+
395
+ title = "theme_";
396
+
397
+ csvFile = Resources.Load("CSV/" + title + dataName) as TextAsset;
398
+
399
+ StringReader reader = new StringReader(csvFile.text);
400
+
401
+
402
+
403
+ while (reader.Peek() > -1)
404
+
405
+ {
406
+
407
+ string line = reader.ReadLine();
408
+
409
+ csvDatas.Add(line.Split(','));
410
+
411
+ Debug.Log("reading:" + height);
412
+
413
+ height++;
414
+
415
+ }
416
+
417
+
418
+
419
+ for (i = 0; i < height; i++)
420
+
421
+ {
422
+
423
+ for (j = 0; j < size; j++)
424
+
425
+ {
426
+
427
+ Debug.Log("csvDatas[" + i + "][" + j + "]:" + csvDatas[i][j]);
428
+
429
+ }
430
+
431
+ }
432
+
433
+
434
+
435
+ QuestionLabelSet();
436
+
437
+ AnswerLabelSet();
438
+
439
+ AnswerSet();
440
+
441
+ }
442
+
443
+
444
+
445
+
446
+
447
+ public void QuestionLabelSet()
448
+
449
+ {
450
+
451
+ csvDatas[k] = csvDatas[Random.Range(0, 9)];
452
+
453
+
454
+
455
+ //特定の名前のオブジェクトを検索してアクセス
456
+
457
+ Text qLabel = GameObject.Find("Quiz/Image/QLabel").GetComponentInChildren<Text>();
458
+
459
+ //データをセットすることで、既存情報を上書きできる
460
+
461
+ qLabel.text = csvDatas[k][0];
462
+
463
+ }
464
+
465
+
466
+
467
+ public void AnswerLabelSet()
468
+
469
+ {
470
+
471
+ //問題文に対応した答えをそれぞれのuGUIボタンにセット
472
+
473
+ string[] array = new string[] { csvDatas[k][1], csvDatas[k][2], csvDatas[k][3], csvDatas[k][4] };
474
+
475
+
476
+
477
+ //問題文をシャッフル
478
+
479
+ array = array.OrderBy(x => System.Guid.NewGuid()).ToArray();
480
+
481
+
482
+
483
+
484
+
485
+ //ボタンが4つあるのでそれぞれ代入
486
+
487
+ for (int i = 1; i <= 4; i++)
488
+
489
+ {
490
+
491
+ Text ansLabel = GameObject.Find("Quiz/AnsButton" + i).GetComponentInChildren<Text>();
492
+
493
+ ansLabel.text = array[i - 1];
494
+
495
+ }
496
+
497
+ }
498
+
499
+
500
+
501
+ public void AnswerSet()
502
+
503
+ {
504
+
505
+ //答えとなるcsvデータを変数として型に代入する
506
+
507
+ AnswerText = csvDatas[k][1];
508
+
509
+ Debug.Log ("アンサーセット'" + AnswerText + "'");
510
+
511
+
512
+
513
+ Kaisetsubun = csvDatas[k][5];
514
+
515
+ Debug.Log(Kaisetsubun);
516
+
517
+ }
518
+
519
+
520
+
521
+ void Update() { }
522
+
523
+ }
524
+
525
+ ```
526
+
267
527
  ### 補足情報
268
528
 
269
529