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

回答編集履歴

2

ソース修正

2020/09/17 02:53

投稿

hogefugapiyo
hogefugapiyo

スコア3307

answer CHANGED
@@ -44,7 +44,7 @@
44
44
  }
45
45
 
46
46
  void ReadFile() {
47
- using (TextReader tr1 = File.OpenText("./Assets/TextData.txt")) {
47
+ using (TextReader tr1 = File.OpenText("../TextData.txt")) {
48
48
  while((boomin = tr1.ReadLine()) != null) {
49
49
  inputDataList.Add(float.Parse(boomin));
50
50
  }

1

補足

2020/09/17 02:53

投稿

hogefugapiyo
hogefugapiyo

スコア3307

answer CHANGED
@@ -22,4 +22,33 @@
22
22
  }
23
23
  }
24
24
  }
25
+ ```
26
+
27
+ #追記
28
+ 長さが決まってないなら、配列じゃなくてListを使うほうが楽だと思います。
29
+ ReadLineがnullってことは行末のはず=それまで読み込めばファイルの全行を読み込む という考えからwhile文で回します
30
+
31
+ ```cs
32
+ using System.Collections;
33
+ using System.Collections.Generic;
34
+ using System.IO;
35
+ using UnityEngine;
36
+
37
+ public class Test : MonoBehaviour {
38
+
39
+ public string boomin;
40
+ public List<float> inputDataList = new List<float>();
41
+
42
+ private void Start() {
43
+ ReadFile();
44
+ }
45
+
46
+ void ReadFile() {
47
+ using (TextReader tr1 = File.OpenText("./Assets/TextData.txt")) {
48
+ while((boomin = tr1.ReadLine()) != null) {
49
+ inputDataList.Add(float.Parse(boomin));
50
+ }
51
+ }
52
+ }
53
+ }
25
54
  ```