using UnityEngine; using System.Collections; using System.IO; //------------------------------------------------------------------------ //Perlin Noise Agents v1.0 - Write File Class //--Class controls the writing of agent Positions to a text file--Class lives inside the GameController Game Object-- //Mode Lab - Written by Luis Quinones //------------------------------------------------------------------------ public class WriteFile : MonoBehaviour { StreamWriter sw; string path = "Assets/Files/"; string filename = "AgentPositions.txt"; private string newfilename; void Start() { if(!Directory.Exists(path)) Directory.CreateDirectory(path); else { if(!File.Exists(filename)) File.Create(path+filename); } } void Update(){ if (Input.GetKey ("f6")) { string theTime = System.DateTime.Now.ToString("hh.mm.ss"); string theDate = System.DateTime.Now.ToString("MM-dd-yyyy"); Application.CaptureScreenshot("Screenshot_" + theTime.ToString() + "_" + theDate.ToString() + ".png",4); Debug.Log ("Took ScreenShot with UI and Exported Text File with Positions"); newfilename = "AgentPositions_" + theTime.ToString() + "_" + theDate.ToString() + ".txt"; WriteToFile(path+newfilename); } } public void WriteToFile(string file) { sw = new StreamWriter(file); GameObject[] test = GameObject.FindGameObjectsWithTag ("AGENTDUDE"); int count = 0; foreach (GameObject t in test) { if (t == null) { Debug.Log ("Cant Find Instance"); } else { sw.WriteLine (t.transform.position.ToString ()); count ++; } } sw.Close (); } } Update