txtファイルに1行ごとに1ステージのデータを入れておいて、
1行ごとに切って配列にして
その配列の(ステージ)番目を読み込んで地面を生成したいのですがエラーが出て動きません。どうすればよいのでしょうか?
Unity 2017.3.1f1です。
あと、こんな感じで表示されてます。
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class CreateGround : MonoBehaviour { 6 public GameObject Gr0Prefab; 7 public TextAsset StageData; 8 int Stage=1; 9 void Start () { 10 StringSplit(); 11 StageData = Resources.Load ("SiromaruCandy") as TextAsset; 12 string StrData = StageData.text; 13 string[] StgData = StrData.Split(char.Parse("\n")); 14 CreateGr(); 15 } 16 void StringSplit(){ 17 18 } 19 // Update is called once per frame 20 void Update () { 21 22 } 23 void CreateGr(){ 24 int len = StgData[Stage-1].Length;//lenをステージデータのStage行目の長さにする 25 int n = 0; 26 while(n < len){//nがlenより小さいなら繰り返す 27 string c= StgData[Stage-1].Substring(0, n+1);//cをステージ行目のn番目の文字にする 28 GameObject gr0 = Instantiate(Gr0Prefab) as GameObject;//gr0にGr0のPrefabを設定する...(Grの数だけやる) 29 string gr="gr"+c;//grをgrとcにする 30 gr.transform.position = new Vector2(540*n, -360);//(Gr)と(c)を生成 x(540*n -270),y(-360) 31 n=n+1;//nを一ずつ変える 32 } 33 } 34} 35
どのようなエラーが出たか記述をお願い致します
回答1件
あなたの回答
tips
プレビュー