Read a certain letter of text file.

I would like to instantiate from the text file. I can make it read, but not in chunks. like fir instance a line:

0,3,0/0,0,0 I would like to read the “0,3,0” as a vector 3 ,and the others as a quaternion, and it be separated by the line. but I don’t know how to read each chunk, just the line.

If you call ReadLine to get a line, you can split the line into multiple parts.

For example, let’s suppose ReadLine gave us the following line:

string line = "0,3,0/0,0,0";

Splitting the vector and quaternion from each other:

string[] recordSeparators = new string[]{"/"};

string[] records = line.Split(recordSeparators);

string vectorRecord = records[0];
string quaternionRecord = records[1];

Splitting those records into fields:

Vector3 StringToVector3(string vectorRecord) {
    string[] fieldSeparators = new string[]{","};
    string[] parts = vectorRecord.Split(fieldSeparators);

    Vector3 vec = Vector3.zero;
    for (int i=0; i<3; i++) {
        float component = 0;
        if (float.TryParse(parts*, out component)) {*

vec = component;
} else {
Debug.LogWarning(“Failed to parse '” + parts + “'”);
}
}

return vec;
}

Quaternion StringToQuaternion(string quaternionRecord) {
Vector3 vec = StringToVector3(quaternionRecord);
return Quaternion.Euler(vec);
}
Don’t forget that a serialization library like JsonFx or MiniJSON can make this sort of work a lot easier. You don’t have to build everything from scratch!