[Solved] Write to text files with c# in Unity3D using StreamWriter

2014-11-11

StreamWriter is very simple tool which let you to write your data into text files.This script is very easy to understand and working method which I have implemented in my Foxes and Rabbit Simulation.Unity3D C#

using UnityEngine; using System.Collections; using System.IO; public class countfox : MonoBehaviour { public int count_fox; StreamWriter sw; GameObject [] fox; void Start(){ sw = new StreamWriter(“count_fox.txt”); //The file is created or Overwritten outside the Assests Folder. } void Update(){ fox = GameObject.FindGameObjectsWithTag(“fox”); count_fox= fox.Length; sw.WriteLine(“ “ + count_fox+” “+System.DateTime.Now, true); sw.Flush(); } }