I am trying to create an example of Unity creating Text files / directories. Can someone point to me the correct function I need to call to have unity create a new file called “Data” or something?
This tool is meant to take a number of GUI textfields, be saved, and then loaded for later use. so simple Text files on the local harddrive is all I need.
Code I have:
var firstnameGUI : First Name;
var lastnameGUI : Surname;
function OnGUI () {
firstnameGUI = GUI.TextField (Rect (25, 80, 150, 30), firstnameGUI);
lastnameGUI = GUI.TextField (Rect (25, 115, 150, 30), lastnameGUI);
if (GUI.Button (Rect (25, 350, 120, 30), "Save User")) {
//create Username
usernameGUI = firstnameGUI.Substring(0,1) + lastnameGUI.Substring(0,1);
//create Folder
if (!Directory.Exists ("C:/Data/" + usernameGUI)) {
Directory.CreateDirectory ("C:/Data/" + usernameGUI);
}
//Create Text file.. but dont know how.. How to create the Text file to save to.
//save to textfile
File.WriteAllText(firstnameGUI, lastnameGUI);
}
}
File.WriteAllText does take two arguments like you’ve supplied, but the first one is the filepath. The text you want to write is the second one. So you need something like,
I have no clue why its erroring on the first letter of the first folder in the path string…?? I tried rebooting Unity but I get the same error… Am I going mad??