Hello,
I have this code that I inherited from a friend,( that I am also asking) but in case he is too busy I was hoping maybe this is a simple problem someone here can answer.
Basically I have this code that can read a CSV file and instantiate the data based on x y z and scale of y. But the problem I am having is that it is not reading decimal points. Does anyone know if this is a simple fix ?
Here is the code:
using UnityEngine;
using System.Collections;
public class Cube : MonoBehaviour {
//This code is used to parse a CSV file and also to spawn objects based on that CSV fi
// Big thanks to Seth Iacangelo aka Dark Shot of FF XIV
public TextAsset csvFile;
public GameObject prefab;
private int index = 0;
private int[] x;
private int[] y;
private int[] z;
void Start(){
Longitude();
}
void Longitude () {
print (csvFile);
string[] numberArray = csvFile.text.Replace("
“[0],”,“[0]).Split(”,"[0]);
int length = (numberArray.Length - 1) / 3;
x = new int[length];
y = new int[length];
z = new int[length];
for(int i = 0; i < numberArray.Length - 1; i++){
switch (i%3) {
case 0:
x [index] = int.Parse (numberArray *);*
-
break;* -
case 1:*
_ y [index] = int.Parse (numberArray );_
* break;*
* case 2:*
_ z [index] = int.Parse (numberArray );
* string name = index.ToString();
GameObject instance = Instantiate(prefab) as GameObject;
instance.transform.position = new Vector3(x[index],y[index],0);
instance.transform.localScale += new Vector3(0,z[index],0);
instance.name = name;
index ++;
break;
}
}
}
}*_
You've got x,y,z declared as ints, and are using
– Owen-Reynoldsint.Parseto read them. Did the original code read ints only? And you're wanting to modify it to read floats? Some of the problem may be that the code is a little wonky. The array isn't used for anything and the switch seems needlessly confusing (why not just read x,y,z together, and have the loop advance byi+=3?) And when do you want x&z scale to be 0, and not 1?