using UnityEngine;
using System;
using System.Collections.Generic;
using System.IO;
using UnityEngine.Rendering;
public class CsvReader : MonoBehaviour
{
List<float> x1 = new List<float>();
List<float> x2 = new List<float>();
List<float> x3 = new List<float>();
List<float> y1 = new List<float>();
List<float> y2 = new List<float>();
List<float> y3 = new List<float>();
int n;
int count;
GameObject Ball1;
GameObject Ball2;
GameObject Ball3;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
TextAsset csvFile;
List<string[]> csvDatas = new List<string[]>(); csvFile = Resources.Load("3body") as TextAsset; // Resouces下のCSV読み込み
StringReader reader = new StringReader(csvFile.text);
Ball1 = GameObject.Find("Ball1");
Ball2 = GameObject.Find("Ball2");
Ball3 = GameObject.Find("Ball3");
while (reader.Peek() != -1)
{
string line = reader.ReadLine();
csvDatas.Add(line.Split(','));
}
n = csvDatas.Count;
count = 0;
for (int i = 0; i < n; i++)
{
x1.Add(Convert.ToSingle(csvDatas[i][0]));
y1.Add(Convert.ToSingle(csvDatas[i][2]));
x2.Add(Convert.ToSingle(csvDatas[i][4]));
y2.Add(Convert.ToSingle(csvDatas[i][6]));
x3.Add(Convert.ToSingle(csvDatas[i][8]));
y3.Add(Convert.ToSingle(csvDatas[i][10]));
}
}
// Update is called once per frame
void Update()
{
if (count > n)
{
count = 0;
}
Ball1.transform.position = new Vector3(x1[count], y1[count], 0f);
Ball2.transform.position = new Vector3(x2[count], y2[count], 0f);
Ball3.transform.position = new Vector3(x3[count], y3[count], 0f);
count++;
}
}
最近のコメント