I am making a building game, to save colors, transforms, and sizes, I would like to make a text document. Im not asking for a large script. but can someone show me an example of how to make a text document via ssscript and maybe edit it?
To do this you will likely want to make use of the System.IO namespace.
Here is a super simple example:
using System.IO;
// ...
void Foo() {
string filePath = Path.Combine(Application.persistentDataPath, "YourData.txt");
string yourText = "Hello World! from " + name;
File.WriteAllText(filePath, yourText);
}
For more information you may find the MSDN useful:
http://msdn.microsoft.com/en-us/library/vstudio/8bh11f1k.aspx
System.IO Documentation Reference
using UnityEngine;
using System.Collections;
using System.IO;
public class WriteTextFile : MonoBehaviour
{
StreamWriter sw;
string path = "Assets/Files/";
string filename = "TextFile.txt";
void Start()
{
if(!Directory.Exists(path))
Directory.CreateDirectory(path);
else
{
if(!File.Exists(filename))
File.Create(path+filename);
}
WriteToFile(path+filename);
}
public void WriteToFile(string file)
{
sw = new StreamWriter(file);
sw.WriteLine("New Text File");
sw.WriteLine ("Line 2");
sw.WriteLine (gameObject.name + " position = " + transform.position.ToString ());
sw.Close ();
}
}