Calling Functions Within A Script?

So far, I am creating a modeling program, similar to blender in which you can create 3D models.

The only problem ive had is exporting in game. I have a .obj exporter script, yet it is a editor script so it is apparently not usable in game!

The ISSUE I NEED YOU TO FIX IS…Calling this function in the script! -

My Code Of Thingy That I Need To Access :

using UnityEngine;
using System.Collections;
using System.IO;
using System.Text;
 
public class ObjExporter : MonoBehaviour {

public ObjExporter script;
public GameObject ToBeExported;
 
    public static string MeshToString(MeshFilter mf) {
        Mesh m = mf.mesh;
        Material[] mats = mf.renderer.sharedMaterials;
 
        StringBuilder sb = new StringBuilder();
 
        sb.Append("g ").Append(mf.name).Append("

");
foreach(Vector3 v in m.vertices) {
sb.Append(string.Format("v {0} {1} {2}
“,v.x,v.y,v.z));
}
sb.Append(”
");
foreach(Vector3 v in m.normals) {
sb.Append(string.Format("vn {0} {1} {2}
“,v.x,v.y,v.z));
}
sb.Append(”
");
foreach(Vector3 v in m.uv) {
sb.Append(string.Format("vt {0} {1}
“,v.x,v.y));
}
for (int material=0; material < m.subMeshCount; material ++) {
sb.Append(”
");
sb.Append("usemtl “).Append(mats[material].name).Append(”
");
sb.Append("usemap “).Append(mats[material].name).Append(”
");

            int[] triangles = m.GetTriangles(material);
            for (int i=0;i<triangles.Length;i+=3) {
                sb.Append(string.Format("f {0}/{0}/{0} {1}/{1}/{1} {2}/{2}/{2}

",
triangles*+1, triangles[i+1]+1, triangles[i+2]+1));*
}
}
return sb.ToString();
}

  • void OnGUI () {*

  • if(GUI.Button(new Rect(60,290,25,200),“Export Creation As .Obj”))*

  • }*

public static void MeshToFile(MeshFilter mf, string filename) {
using (StreamWriter sw = new StreamWriter(filename))
{
sw.Write(MeshToString(mf));
}
}
}
Basically, I need to call this function at the bottom of the script from a C#, (I could also do it from a JAVA script if thats the only thing you can help with!)
CALL THIS FUNCTION…
public static void MeshToFile () {

Just don’t put that function in an editor script. You can call things from other places.

ClassName.StaticFunctionName()