I have a file, NewAsteroid001.raw, which contains 6 elements per line, coordinates (x,y,z) and lengthes (x,y,z) the lengths are currently 1.
I wanted Unity to load the file, parse it, and place cubes at each location.
When it finished, I wanted to export the completed object as an OBJ file.

I have the following code

using UnityEngine;
using System.Collections;
using System.Text;
using System.IO;

public class PlaceCubes : MonoBehaviour
{
    void Start()
    {
        var Combine1 = new MeshFilter();
        var fileName = "c:\\assets\\NewAsteroid001.raw";
        var sr = new StreamReader(fileName);
        var fileContents = sr.ReadToEnd();
        sr.Close();
        var lines = fileContents.Split("

"[0]);
foreach (string line in lines)
{
var Elements = line.Split(‘,’);
var XCoord = float.Parse(Elements[0]);
var YCoord = float.Parse(Elements[1]);
var ZCoord = float.Parse(Elements[2]);
var XLen = float.Parse(Elements[3]);
var YLen = float.Parse(Elements[4]);
var ZLen = float.Parse(Elements[5]);
var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
cube.transform.position = new Vector3(XCoord, YCoord, ZCoord);
cube.transform.localScale = new Vector3(XLen, YLen, ZLen);
cube.transform.parent = Combine1.transform;
}
ObjExporter.MeshToFile(Combine1, “c:\assets\NewAsteroid001.obj”);
}
}

I then created the scene, placed a cube as a game object and attached said code.
I tried running, and I get no file. I am not even sure all the cubes are being placed or that this script is even running.

I put a debug.break into the code, hoping that would stop and show me it was working, but that did not help either.

Any idea what I am doing wrong here…

BTW, I am new to both Unity and to c#. I am hoping that the unity engine will work better then my previous game engine, and learning c# should not be hard for me in the long run.

Thanks in advance for any help.

This will help you : Unity - Scripting API: Application.dataPath

Make sure the file is in the correct folder and use single forward slashes.

Making above mentioned changes made it work.