実現したいこと
現在、テキストファイルを読み込み、Tilemapでタイルを動的に配置するということをしております。
実行前はエラーがないのですが、実行時にIndex was outside the bounds of the array.が発生します。
どうやら、switch文での判別が上手くいっていないようなのです。”\n”と言う書き方が不味いのかもしれません。
しかし、どう書いていいのかも分かりません。知識のある方どうか教えてくださいませんでしょうか。
C#
1public void ReadFile(){ 2 FileStream fs = null; 3 4 fs = new FileStream(filename, FileMode.Open); 5 6 GameObject.Destroy(dt.gameObject); 7 using(StreamReader sr = new StreamReader(fs, System.Text.Encoding.GetEncoding("UTF-8"))) 8 { 9 10 int i = 0,j = 0,ch; 11 while((ch = sr.Read()) != -1) 12 { 13 14 Vector3Int tilepos = new Vector3Int(i, j, 0); 15 Tile tile = null; 16 switch(ch.ToString()){ 17 case "_": 18 break; 19 case "C": 20 tile = Resources.Load<Tile>("Tile_Palette/Core_tile"); 21 break; 22 case "E": 23 tile = Resources.Load<Tile>("Tile_Palette/Entrance_tile"); 24 break; 25 case "S": 26 tile = Resources.Load<Tile>("Tile_Palette/Soil_tile"); 27 break; 28 case "T": 29 tile = Resources.Load<Tile>("Tile_Palette/Terrain_tile"); 30 break; 31 case "W": 32 tile = Resources.Load<Tile>("Tile_Palette/Water_tile"); 33 break; 34 case "\n": 35 i = 0; 36 j++; 37 break; 38 } 39 Debug.Log(i + "," + j); 40 dt.Dungeontile.SetTile(tilepos, tile); 41 tm.tile[i, j] = tile; 42 i++; 43 } 44 } 45 }
確認したこと
テキストファイルに改行があること
自身のパソコンがMacであること
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/04/11 09:14