Hi so i have this line of code:
Vector3 waypoint = new Vector3 (float.Parse(coordinates[0], CultureInfo.InvariantCulture), 0.5f, float.Parse(coordinates[1], CultureInfo.InvariantCulture))
And i get the error in the title of the thread. When i read the original .txt file however. If i copy and paste the contents of a the .txt file it works fine I’m kinda unsure one what to do it as it could be the way that i’m creating the file.
The file contents for example are the following =:
12.3,12.6
-2.2,-3.4
2,1
2.4,-4.5
Etc…
Debug.Log is your friend.
Before you run some text through float.Parse
, print it out and make sure it looks ok. Empty strings, or strings that don’t contain any numbers are not alright. Also any strings that have commas in them not at 3 character intervals will probably not work as it may be mistaken for a wrong decimal separator.
TL;DR - print out what you’re trying to parse and see what’s going wrong.
2 Likes
And don’t forget invisible characters such as spaces or tabs or carriage return / newline.
Parsing text can get very tricky, but as Praetor says, Debug.Log is your friend. I like to put extra tick-marks in to make sure what I’m parsing is “tight” and not bounded by whitespace:
Debug.Log( "I'm going to parse '" + DataString + "'");
2 Likes