我正在尝试根据csvfile中的数据在屏幕上移动一个多维数据集,但它不起作用。有人可以帮我这个代码吗?
使用UnityEngine;
public class LeitorCSV : MonoBehaviour
{
public GameObject cubeTest;
public TextAsset csvFile;
// Update is called once per frame
void Update()
{
ReadCSV();
}
private void ReadCSV()
{
string[] records = csvFile.text.Split('\n');
for (int i = 1; i < records.Length; i++)
{
string[] fields = records[i].Split(',');
cubeTest.transform.Translate(float.Parse(fields[1]),
float.Parse(fields[2]), float.Parse(fields[3]));
}
}
}
我试过这种方式也没办法。
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.IO;
using System.Collections.Generic;
public class leitorCSV2 : MonoBehaviour
{
public GameObject cubeTest;
public TextAsset csvFile;
// Update is called once per frame
void Update()
{
readCSV();
}
void readCSV()
{
string[] records = csvFile.text.Split('\n');
for (int i = 1; i < records.Length; i++)
{
string[] fields = records[i].Split(',');
float x = float.TryParse(fields[1], out x) ? x : 0;
float y = float.TryParse(fields[2], out y) ? y : 0;
float z = float.TryParse(fields[3], out z) ? z : 0;
cubeTest.transform.Translate(new Vector3(x, y, z) *
Time.deltaTime);
}
}
}