Hi,
In my external file, I have this unique and short line:
001///526.9785///918.133///001///1484.1///397.38///
You can read it like this:
type1///x coordinate of type0///y coordinate of type0///type2///x coordinate of type1///y coordinate of type1
I successfully get Unity to read the file and return this a single string variable; this is not a problem in any way.
However, I must split this retrieved string to smaller chunks so that I can store the string values seperately in variables, just like this:
string xoffirstobject = x coordinate of type0;
string yoffirstobject = y coordinate of type0;
string xofsecondobject = x coordinate of type1;
string yofsecondobject = y coordinate of type1;
I am new to multi-dimensional arrays, and all answers that could help me understand are mainly coded in Javascript or too specific to somebody else’s situation, and I am coding in C# only. I tried to understand the Javascript examples (did many tests to adapt their code) for 7 hours now but all I tried to find is a huge headache…
How to proceed? Here below I post my code. Don’t take much attention to my actual syntax, I know it is not logic or returning a 2D array, but instead please tell me how to achieve this in the actual context.
Here it is (sorry I do not include variable declarations):
if(GUI.Button(new Rect(90,10,70,30), "Load..."))
{
//Retrieve the text from the external text file and store it in a string variable
theSourceFile = new FileInfo ("C:/unityexport/test.txt");
reader = theSourceFile.OpenText();
text = reader.ReadLine();
reader.Close();
//I set u<3 because I have only 2 types currently in my external text file. But this is the part that is not working properly.
for (int u=1;u<3;u++)
{
string[] dataLinestype = text.Split("///");
string[] dataLinesx = text.Split("///"[0]);
string[] dataLinesy = text.Split("///"[0]);
Debug.Log("............................ type: " + dataLinestype + " x: " + dataLinesx[0] + " y: " + dataLinesy[0]);
}
}
NOTE that I am generating the text file myself, so I can put any seperating character at any desired position if this is a problem. I want the most simple-to-understand way.
Please help me!