- Home /
Read variable from txt to Vector3
Hi there !
I have a .txt file containing 3D coordinates. I want to put they into vector3 in unity
How must I do?
PosCoin 1 : 5.44,-1.28,-0.32
PosCoin 2 : 4.80,-1.92,-0.32
PosMobil 1 : 2.88,1.28,-0.32
PosMobil 2 : 1.60,1.92,-0.32
PosBajaj 1 : 2.88,-0.64,-0.32
PosBajaj 2 : 2.24,-1.92,-0.32
element 1 : x axis
element 2 : y axis
element 3 : z axis
Thanks
Answer by paulaceccon · Feb 26, 2013 at 01:45 PM
Assuming that you know how to read an archive (easy to search and find), you could use the string.Split method. The, you could make a Split(':'). This you break your string in two parts, one before the ':' character, and one after this character. So, you will have something like:
string[] myString = myArchiveLine.Split(':')
Then, you know that the data that you want is in the second position of the string. So, like before;
string[] myData = myString[1].Split(',')
Now, you will break the string in the ',' character. So, you will have your data like this:
x in myData[0]
y in myData[1]
z in myData[2]
Your answer
Follow this Question
Related Questions
How can I read data from a text file, putting a large amount of data into structures 2 Answers
Getting A Variable From a Outside Text File 1 Answer
Best way to manage stats in a text file 2 Answers
How do I place the matching Vector3 array values of a Vector3 array in a new array ? 1 Answer
Edit one element in Vector3 array 1 Answer