質問失礼します。
Unityで時間を計測し、計測した値をテキストファイルに書き込むプログラムを作成しようとしています。
他のサイトを参考に作成してみたのですが、テキストファイルに書き込まれない状態です。
C#
1using System.Collections; 2using UnityEngine; 3using System.Collections.Generic; 4using System.IO; 5 6public class Logtime : MonoBehaviour 7{ 8 9 10 float time; 11 bool start = false; 12 13 // 引数でStringを渡してやる 14 15 16 17 void Start() 18 { 19 time = 0; 20 } 21 void Update() 22 { 23 if (Input.GetMouseButtonDown(0) && !start) 24 { 25 26 start = true; 27 Debug.Log("スタート"); 28 } 29 30 float translation = Input.GetAxis("Vertical"); 31 if (translation < 0 && start) 32 { 33 Debug.Log(time.ToString("F3")); 34 35 36 } 37 if (start) 38 time += Time.deltaTime; 39 } 40 41 public void textsave(string txt) 42 { 43 FileInfo fi = new FileInfo(Application.dataPath + "Scripts/test.csv"); 44 StreamWriter sw = fi.AppendText(); 45 sw.WriteLine(time.ToString("F3")); 46 sw.Flush(); 47 sw.Close(); 48 49 } 50 51}
時間はコンソールに正しく出力されます。
テキストファイルの保存先は、Assets内にあるScriptsの中で名前はtest.csvです。
改善点が分かる方、ご指導の程お願いします。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/12/04 08:22
2017/12/04 09:44