###前提・実現したいこと
プログラム初心者です。
Unityにて、csvを読み取ってテキストに反映させるプログラムを作りたいと思っているのですが、エラーが出てきてしまいます。
エラーの内容もよくわからなく、どうすればいいかわかりません。
解決方法をご教授ください。
###発生している問題・エラーメッセージ
NullReferenceException: Object reference not set to an instance of an object ScoreManager.LoadCSV () (at Assets/Scripts/ScoreManager.cs:29) ScoreManager.Start () (at Assets/Scripts/ScoreManager.cs:16)
###該当のソースコード
c#
1using System.Collections; 2using System.IO; 3using System; 4using UnityEngine.UI; 5using UnityEngine; 6 7public class ScoreManager : MonoBehaviour { 8 9 public Text[] _Name; 10 public Text[] _Score; 11 public string filePass; 12 13 // Use this for initialization 14 void Start () { 15 LoadCSV (); 16 17 } 18 19 // Update is called once per frame 20 void Update () { 21 22 } 23 24 void LoadCSV () { 25 int i = 0, j; 26 TextAsset csv = Resources.Load (filePass) as TextAsset; 27 Debug.Log (filePass); 28 StringReader reader = new StringReader (csv.text);//←ココ 29 while (reader.Peek () > -1) { 30 31 string line = reader.ReadLine (); 32 string[] values = line.Split (','); 33 _Name [i].text = (values [0]); 34 _Score [i].text = (values [1]); 35 Debug.Log ("i = " + i); 36 i++; 37 38 } 39 40 } 41 42}
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/09/06 09:05