Advertisemen
Animating object with CSV / TXT file in Unity 3d
This will give you the basic idea on how to use CSV file in unity 3d and create animation from its contents.
Copy and paste the codes used in this video :
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.IO;
public class CSVFIleReader : 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(',');
cubeTest.transform.Rotate (float.Parse(fields[1]), float.Parse(fields[2]), float.Parse(fields[3]));
}
}
}
using System.Collections;
using UnityEngine.UI;
using System.IO;
public class CSVFIleReader : 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(',');
cubeTest.transform.Rotate (float.Parse(fields[1]), float.Parse(fields[2]), float.Parse(fields[3]));
}
}
}
Please don't forget to subscribe and share.
Advertisemen
Tidak ada komentar:
Posting Komentar