EDITED --- 내 foreach 루프에서 2D 배열에 값을 추가하는 데 문제가 있습니다. 하리는 루프 앞에 i = 0과 배열을 선언 할 필요가 있다고 지적했고 값의 배정을 거꾸로 잡았다 고 지적했습니다. (고맙습니다). 그러나 최종 강도 배열 및 Debug.Log i 및 콘솔의 값을 추가하려고했습니다 "System.Single []"단일 값 대신 읽습니다. 왜 그런지 아십니까? 감사합니다! 여기 텍스트 파일에서 2D 배열로 값 추가 C#
내 코드입니다 : 요소는 다음 값을 포함하지 않는 경우 먼저 배열을 당신이coordinateX
에 할당하는
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
//[Serializable]
public class MultiArrayList2 : MonoBehaviour {
public TextAsset datafile;
private int i;
private float[,] coordinates;
private float[] intensity;
// Use this for initialization
void Start() {
string[] dataLines = datafile.text.Split ('\n');
string[] lineValues;
//print (dataLines.Length);
i=0;
float[,] coordinates = new float[6853, 3];
float[] intensity = new float[6853];
foreach (string line in dataLines) {
lineValues = line.Split (' ');
float coordinateX = float.Parse (lineValues [0]);
float coordinateY = float.Parse (lineValues [1]);
float coordinateZ = float.Parse (lineValues [2]);
float intens = float.Parse (lineValues [3]);
coordinates [i, 0] = coordinateX;
coordinates [i, 1] = coordinateY;
coordinates [i, 2] = coordinateZ;
intensity [i] = intens;
Debug.Log (intensity);
i++;
}
}
}
대단히 감사합니다! 그것은 효과가있다! – jrogers12
도와 줘서 기쁘다. 도움이된다면 답으로 표시하면 문제의 해결책이됩니다. –