i am using unity v2018 on a msi laptop i5, 8th gen, windows 10, graphics card NVIDIA geforce 1050. I am impoting a csv file with time and x axis and y axis positions. I am trying to move the object to the specified position based on time from the CSV file to create a real time-interaction. I have used the following code to do the same:
code:
void Start ()
{
TextAsset time = Resources.Load(“time”);
string[ ] data = time.text.Split (new char[ ] { ‘\n’ });
for (int i = 1; i < data.Length - 1; i++)
{
string[ ] row = data*.Split(new char[ ] { ‘,’ });*
Data q = new Data();
int.TryParse(row[0],out q.time);
int.TryParse(row[1],out q.x);
int.TryParse(row[2],out q.z);
pos.Add(q);
if (q.time == 0)
transform.position = transform.position + new Vector3(q.x * movementSpeed * Time.deltaTime, 0, q.z * movementSpeed * Time.deltaTime);
if (q.time == 10)
transform.position = transform.position + new Vector3(q.x * movementSpeed * Time.deltaTime, 0, q.z * movementSpeed * Time.deltaTime);
if (q.time == 20)
transform.position = transform.position + new Vector3(q.x * movementSpeed * Time.deltaTime, 0, q.z * movementSpeed * Time.deltaTime);
}
}
This is the class i used for importing:
public class Data
{
public int time;
public int x;
public int z;
}
this is the csv file:
time, x, z
0, 0, 0
10, 10, 20
20, 20, 10
Instead of the object moving twice to different positions the object is moving finally to a position which seems to be the sum of the two positions i provided, i.e. 30,30 here.
what should i change to get the desired output.