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


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]